Skip to content

G-7720: Never use multiple UPDATE OF in trigger event clause.

Blocker

Maintainability, Reliability, Testability

Reason

A DML trigger can have multiple triggering events separated by or like before insert or delete or update of some_column. If you have multiple update of separated by or, only one of them (the last one) is actually used and you get no error message, so you have a bug waiting to happen. Instead you always should use a single update of with all columns comma-separated, or an update without of if you wish all columns.

Example (bad)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
create or replace trigger dept_br_u
before update of department_id or update of department_name
on departments for each row
begin
   -- will only fire on updates of department_name
   insert into departments_log (department_id
                               ,department_name
                               ,modification_date) 
                        values (:old.department_id
                               ,:old.department_name
                               ,sysdate);
end;
/

Example (good)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
create or replace trigger dept_br_u
before update of department_id, department_name
on departments for each row
begin
   insert into departments_log (department_id
                               ,department_name
                               ,modification_date) 
                        values (:old.department_id
                               ,:old.department_name
                               ,sysdate);
end;
/