I want to make a trigger that sets the joined attribute to the current year. This is what I have working:
CREATE OR REPLACE TRIGGER foo2
BEFORE INSERT ON memberof
FOR EACH ROW
BEGIN :new.joined := 2012;
END;
I want to change 2012 to the code below but keep getting compiler errors. What’s the proper syntax to accomplish this?
select extract(year from sysdate) from dual
This should do the trick:
For more information see here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm
and here: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm
BTW OMG Ponies is correct this normally should be done with default values which can take an expression like
as well.