Search code examples
sqloracle-databaseoracle9i

SQL want to log values before and after update table


I have a problem here.

DB: oracle 9i

I want to save data changes after I execute UPDATE script on my table, in that log I want to compare old values with new values.

How can i do this.

thanks for helping me :)


Solution

  • write simple trigger, by using :OLD and :NEW you can get the value of both new and old value of the table

     create or replace
     trigger tg_name
      after UPDATE ON table_name
     for each row
     BEGIN
     IF :NEW.column1 = :OLD.column1 THEN
     -- any statement 
     END IF;    
    -- you can log the old and new value by inserting into log table's too..
    END;