Q
Problem solve Get help with specific problems with your technologies, process and projects.

Triggers and spooling data

I would like to create a trigger that fires on update or delete of column data. I then would like to spool to another table which column was updated, the old value and the new value. How might I go about doing this?
The trick to this one is to use the "new" and "old" values of the column that is being deleted. I'll show you an example of how you do this.

CREATE TRIGGER my_table_trigger
BEFORE update OR delete ON my_table
FOR EACH ROW
DECLARE
  today DATE;
BEGIN
   -- Get today's date and time
   SELECT sysdate INTO today FROM dual;
   -- Insert new and old values into other table
   INSERT INTO other_table 
     
VALUES(today,:new.col1,:old.col1,:new.col2,:old.col2);
END;
/

Hopefully, you can see how I used the ':new' or the ':old' clause on the column name to specify the new value for the column and the old value for the column.

Dig Deeper on Oracle database design and architecture

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close