0

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 / 

1 Answer 1

1

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; / 
Sign up to request clarification or add additional context in comments.

2 Comments

To change values on-the-fly, the trigger must be BEFORE and yossi wants to include UPDATE statements, so it must be BEFORE INSERT OR UPDATE ON VIRTUAL_COUNTERS FOR EACH ROW.
@acesargl Right you are

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.