2 Day Developer > Using Triggers > Overview of Triggers > Detecting the DML Operation...
Detecting the DML Operation That Fired a Trigger |
Previous |
Next |
If more than one type of DML operation can fire a trigger, such as ON
INSERT
or UPDATE
, the trigger body can use the conditional predicates INSERTING
, DELETING
, and UPDATING
to check which type of statement fires the trigger.
Within the code of the trigger body, you can execute blocks of code depending on the kind of DML operation that fired the trigger. For an example of INSERTING
and UPDATING
predicates, see Example: Creating a Trigger That Fires Only Once.
In an UPDATE
trigger, a column name can be specified with an UPDATING
conditional predicate to determine if the named column is being updated. For example, assume a trigger is defined as the following:
CREATE OR REPLACE TRIGGER ...
... UPDATE OF salary ON employees ...
BEGIN
... IF UPDATING ('salary') THEN ... END IF;
...
The code in the THEN
clause runs only if the triggering UPDATE
statement updates the salary
column. This way, the trigger can minimize its overhead when the column of interest is not being changed.