Line | Description |
1 | States that a trigger is to be created with the name supplied. Specifying OR REPLACE is optional. If the trigger exists and REPLACE is not specified, then your attempt to create the trigger anew will result in an ORA-4081 error. It is possible, by the way, for a table and a trigger (or a procedure and a trigger, for that matter) to have the same name.I recommend, however, that you adopt naming conventions to avoid the confusion that will result from this sharing of names. |
2 | Specifies if the trigger is to fire BEFORE or AFTER the statement or row is processed. |
3 | Specifies the combination of DML types to which the trigger applies: insert, update, or delete. Note that UPDATE can be specified for the whole record or just for a column list separated by commas. The columns can be combined (separated with an OR) and may be specified in any order. Line 3 also specifies the table to which the trigger is to apply. Remember that each DML trigger can apply to only one table. |
4 | If FOR EACH ROW is specified, then the trigger will activate for each row processed by a statement. If this clause is missing, the default behavior is to fire only once for the statement (a statement-level trigger). |
5 | An optional WHEN clause that allows you to specify logic to avoid unnecessary execution of the trigger. |
6 | Optional declaration section for the anonymous block that constitutes the trigger code. If you do not need to declare local variables, you do not need this keyword. Note that you should never try to declare the NEW and OLD pseudorecords.This is done automatically. |
7-8 | The execution section of the trigger. This is required and must contain at least one statement. |
9 | Optional exception section. This section will trap and handle (or attempt to handle) any exceptions raised in the execution section only. |
10 | Required END statement for the trigger. You can include the name of the trigger after the END keyword to explicitly document which trigger you are ending. |