plsql - How to get updated columns indices on BEFORE UPDATE trigger on Oracle? -


in application users can update datas. , want save updated columns values in ag_table_update_history table. table's structure that:

create table "ag_table_update_history"   (     "table_name"     varchar2(20 byte),     "row_id"         varchar2(20 byte),     "column_name"    varchar2(20 byte),     "previous_value" varchar2(20 byte),     "current_value"  varchar2(20 byte)   ) 

i know that, can updated column's names comparing :old , :new columns 1 one in before update trigger. but, want know there better way offered oracle?

the answer depends on want keep values changed in update statement or want track fact columns have been updated. oracle suggests updating() function works in triggers, maybe can help:

sql> create table t (x int, y varchar2(10), z date)   2  /  sql> insert t values(1,'a',sysdate)   2  /  sql> create or replace trigger tr_t   2  before update on t   3  each row   4  begin   5    if updating('x')   6      dbms_output.put_line('old x '||:old.x);   7      dbms_output.put_line('new x '||:new.x);   8    end if;   9    if updating('y')  10      dbms_output.put_line('old y '||:old.y);  11      dbms_output.put_line('new y '||:new.y);  12    end if;  13    if updating('z')  14      dbms_output.put_line('old z '||:old.z);  15      dbms_output.put_line('new z '||:new.z);  16    end if;  17  end;  18  /  sql> set serveroutput on sql> update t set x = 2; old x 1                                                                       new x 2                                                                        1 row updated.  sql> update t set x = 1, y='c'; old x 2                                                                       new x 1                                                                       old y                                                                       new y c                                                                        1 row updated.  sql> update t set x = 1, y='c', z = sysdate+1; old x 1                                                                       new x 1                                                                       old y c                                                                       new y c                                                                       old z 14.04.14                                                                new z 15.04.14                                                                 1 row updated. 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -