Oracle Trigger Updating a field in Insert or Update

For some reason, I am launching a space on how to do something like this.

I have a table that looks like this:

UserID | Name | DateAdded | LastUpated -------------------------------------------------- 1 | James Q | 1/1/2009 | 

If I insert or update a record, the latest update should be updated by sysdate. How can I do something like this?

+7
oracle triggers
source share
2 answers
 CREATE OR REPLACE TRIGGER your_trigger_name BEFORE INSERT OR UPDATE ON your_table FOR EACH ROW DECLARE BEGIN :new.LastUpdated := sysdate; END; 

Give it a try. I did not have an oracle server at hand, but I hope I got the correct syntax.

+12
source share

create or replace mytable_bi trigger before inserting on the table for each row start

: NEW.lastupdated: = sysdate ();

end;

create or replace mytable_bu trigger before updating to mytable for each row start

: NEW.lastupdated: = sysdate ();

end;

0
source share

All Articles