yossi
yossi

Reputation: 3164

Oracle trigger - update column on newly inserted record

In My Oracle (Express) DB I have a table with a column, named created(date type).
What I am trying to do, is to create a trigger that will update that column after an update or insert, was done, with SYSDATE.

My sql (for insert only, I know, it fails anyway) is:

CREATE OR REPLACE TRIGGER  "VIRTUAL_COUNTERS_NEW" 
AFTER
insert on "VIRTUAL_COUNTERS"
begin
new.updated := SYSDATE
end;
/
ALTER TRIGGER  "VIRTUAL_COUNTERS_NEW" ENABLE
/

Upvotes: 0

Views: 3065

Answers (1)

vc 74
vc 74

Reputation: 38179

You need to prefix new with a colon character and add for each row so that the update is for each row in case of multiple rows insert:

CREATE OR REPLACE TRIGGER  VIRTUAL_COUNTERS_NEW
BEFORE
insert on VIRTUAL_COUNTERS
FOR EACH ROW
begin
  :new.updated := SYSDATE;
end;
/

Upvotes: 1

Related Questions