I would like to use a trigger on a table which will be fired every time a row is inserted, updated, or deleted.
I wrote something like this:
CREATE or REPLACE TRIGGER test001
AFTER INSERT OR DELETE OR UPDATE ON tabletest001
REFERENCING OLD AS old_buffer NEW AS new_buffer
FOR EACH ROW WHEN (new_buffer.field1 = 'HBP00')
and it works. Since I would like to do the same things if the row is inserted, updated, or deleted, I would like to know what's happening in the trigger. I think I can manage to find if the row is inserted or updated (I can check the old_buffer with the new_buffer). How can I know if the row has been deleted?
Separate it into 2 triggers. One for the deletion and one for the insertion\ update.
The NEW values (or NEW_BUFFER as you have renamed them) are only available when INSERTING and UPDATING. For DELETING you would need to use OLD (OLD_BUFFER). So your trigger would become:
You may need to add logic inside the trigger to cater for code that updates field1 from 'HBP000' to something else.
From Using Triggers:
So
should work for your case.
I've changed my code like this and it works: