1

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
4

1 に答える 1

2

これでうまくいくはずです:

CREATE OR REPLACE TRIGGER foo2
BEFORE INSERT ON memberof
FOR EACH ROW
BEGIN 
    :new.joined := to_char(sysdate,'YYYY');
END;

詳細については、http: //docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htmを参照してください。

そしてここ:http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm

BTW OMG Poniesは正しいです。これは通常、次のような式を取ることができるデフォルト値で行う必要があります

to_char(sysdate,'YYYY') 

同じように。

于 2012-05-29T05:02:46.043 に答える