Link to home
Start Free TrialLog in
Avatar of evotsi
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
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sean Stuber
Sean Stuber

oops, forgot about the "if specified" part

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;
Avatar of evotsi

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.