The following example of a compound trigger records a change to the employee salary by defining a compound trigger (named hr_trigger) on the emp table.
First, create a table named emp.
Then, create a compound trigger named hr_trigger. The trigger utilizes each of the four timing-points to modify the salary with an INSERT, UPDATE, or DELETE statement. In the global declaration section, the initial salary is declared as 10,000.
INSERT the record into table emp.
The INSERT statement produces the following output:
The UPDATE statement will update the employee salary record, setting the salary to 15000 for a specific employee number.
The UPDATE statement produces the following output:
The DELETE statement deletes the employee salary record.
The DELETE statement produces the following output:
The TRUNCATE statement removes all the records from the emp table.
The TRUNCATE statement produces the following output:
Note
The TRUNCATE statement may be used only at a BEFORE STATEMENT or AFTER STATEMENT timing-point.
The following example creates a compound trigger named hr_trigger on the emp table with a WHEN condition that checks and prints employee salary whenever a INSERT, UPDATE, or DELETE statement affects the emp table. The database evaluates the WHEN condition for a row-level trigger, and the trigger is executed once per row if the WHEN condition evaluates to TRUE. The statement-level trigger is executed irrespective of the WHEN condition.
Insert the record into table emp.
The INSERT statement produces the following output:
The UPDATE statement will update the employee salary record, setting the salary to 7500.
The UPDATE statement produces the following output:
The DELETE statement deletes the employee salary record.
The DELETE statement produces the following output: