Create trigger t_qd_set_date
before insert
On t_qd
for each row
Begin
when (new.sj = '' or new.sj is null)
begin
:new.sj = to_char(sysdate,'yyyy-MM-dd HH:mm:ss')
end
End;
我是这么写的触发器。不知道有没错没。
Create trigger t_qd_set_date before insert On t_qd for each row Begin when (new.sj = '' or new.sj is null) begin :new.sj = to_char(sysdate,'yyyy-MM-dd HH:mm:ss') end End; 我是这么写的触发器。不知道有没错没。 最初问题是,我想在hibernate中操作插入。但是如果字段不给值的话,hibernate默认为“”,而不能使用建表时的
[Quote=引用 1 楼 tangren 的回复:]
SQL code
--这样就行了
CREATE OR REPLACE TRIGGER t_qd_set_date
BEFORE INSERT ON t_qd
FOR EACH ROW
BEGIN
IF :new.sj IS NULL THEN
:new.sj := to_char(SYSDATE, 'yyyy-mm-dd hh24:mm:ss');
END ……
[/Quote]
--这样就行了
CREATE OR REPLACE TRIGGER t_qd_set_date
BEFORE INSERT ON t_qd
FOR EACH ROW
BEGIN
IF :new.sj IS NULL THEN
:new.sj := to_char(SYSDATE, 'yyyy-mm-dd hh24:mm:ss');
END IF;
END;
/