evotsi
asked on
Oracle trigger to change last_modified column of table
I have an Oracle table called PRODUCTS. I need a trigger that will update the last_modified column in this table whenever an UPDATE or INSERT occurs and the last_modified column isn't specified. If it is specified I would like the date entered to be used.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The one with "if specified" works the first time, but after that it doesn't change the date. The first one works perfect, but overrides any date setting. However after looking at the use case there shouldn't be any circumstance where I would need to alter the last_modified column so that should work.
create or replace trigger trg_products_briu
before insert or update
on products
for each row
begin
if :new.last_modified is null then
:new.last_modified := sysdate;
end if;
end;