clause define the timing point for the trigger, which is explained below.
This trigger will display the salary difference between the old values and new values − 0) DECLARE sal_diff number; BEGIN sal_diff := : NEW.salary - : OLD.salary; dbms_output.put_line('Old salary: ' || : OLD.salary); dbms_output.put_line('New salary: ' || : NEW.salary); dbms_output.put_line('Salary difference: ' || sal_diff); END; / Because this is a new record, old salary is not available and the above result comes as null.
Let us now perform one more DML operation on the CUSTOMERS table.
The "dml-event" can be one or more of the following.
CREATE OR REPLACE TRIGGER my_test_trg BEFORE INSERT OR UPDATE OR DELETE ON my_table FOR EACH ROW BEGIN -- Flags are booleans and can be used in any branching construct. If you need some code to perform an operation that needs to commit, regardless of the current transaction, you should put it in a stored procedure defined as an autonomous transaction, shown here.
Each trigger extends a collection defined in the package and stores a message with the trigger name and the current action it was triggered with.
In addition, the after statement trigger displays the contents of the collection and empties it.
Of those, the majority are related to people misunderstanding the order of the timing points and how they are affected by bulk-bind operations and exceptions.
This article represents the bare minimum you should understand about triggers before you consider writing one.
Triggers are stored programs, which are automatically executed or fired when some events occur.