• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1062
  • Last Modified:

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.
0
evotsi
Asked:
evotsi
  • 2
1 Solution
 
sdstuberCommented:
create or replace trigger trg_products_briu
before insert or update
on products
for each row
begin
     :new.last_modified := sysdate;
end;
0
 
sdstuberCommented:
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;
0
 
evotsiAuthor Commented:
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.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now