Oracle: excluding updates of one column for firing a trigger

前端 未结 4 420
执念已碎
执念已碎 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条回答
  •  悲哀的现实
    2021-01-04 14:42

    You could do something like this:

    create or replace trigger my_trigger
    before update on my_table
    for each row
    declare
       n_cols integer := 0;
    begin
       for r in (select column_name from all_tab_columns
                 where table_name = 'MY_TABLE'
                 and owner = 'MY_SCHEMA')
       loop
          if updating(r.column_name) then
             n_cols := n_cols + 1;
             exit when n_cols > 1;
          end if;
       end loop;
       if n_cols > 1 then
          do_something;
       end if;
    end;
    

    Probably not terribly efficient though!

提交回复
热议问题