Oracle: excluding updates of one column for firing a trigger

前端 未结 4 438
执念已碎
执念已碎 2021-01-04 14:20

In oracle I can specify the columns, which should induce a firing of a trigger:

create or replace trigger my_trigger
before update of col1, col2, col3 on my_         


        
4条回答
  •  Happy的楠姐
    2021-01-04 14:41

    I had the same problem yesterday. I wanted to code a trigger that fired on every field except one, the table had 103 colums.

    First I coded:

    if (:OLD.col1<>:NEW.col1 or :OLD.col2<>:NEW.col2 or :OLD.col3<>:NEW.col3 ....)
    

    But I had some problems with null values, so I added:

    if (NVL(:OLD.col1,0)<>NVL(:NEW.col1,0) or NVL(:OLD.col2,0)<>NVL(:NEW.col2,0)  ....)
    

    But then I had some problems with DATE columns, it became a mess..

    I think that the best solution is to list all columns that you want to verify in the "OF":

    AFTER INSERT OR UPDATE of cOL1, col2, col3 ... colN ON table1
    

    It was not "elegant" but... it worked perfect.

提交回复
热议问题