0

我们可以在 HSQL DB 中创建具有多个 WHEN 子句的触发器吗?像这样的东西:-

CREATE TRIGGER  perosn_trig AFTER UPDATE ON person
REFERENCING  NEW AS nwrow  OLD as oldrow
FOR EACH ROW 
   when ( nwrow.person_id>100 )  
   ( insert into TRIGLOG values ('PERSON_more_than_100',nwrow.person_id,SYSDATE)  ),
   When (nwrow.person_id<=100) 
   ( insert into TRIGLOG values ('PERSON_less_than_100',nwrow.person_id,SYSDATE) )
;

此查询给出语法错误。什么是正确的语法?

4

1 回答 1

1

目前不支持触发器中的多个 WHEN 子句。WHEN 子句通常与简单条件一起使用,仅在必要时调用触发器。

对于更复杂的条件,请使用 CASE 或 IF 条件:

CREATE TRIGGER  perosn_trig AFTER UPDATE ON person
REFERENCING  NEW AS nwrow  OLD as oldrow
FOR EACH ROW 
BEGIN ATOMIC
  IF ( nwrow.person_id>100 ) THEN 
    insert into TRIGLOG values ('PERSON_more_than_100',nwrow.person_id,SYSDATE);
  ELSE
    insert into TRIGLOG values ('PERSON_less_than_100',nwrow.person_id,SYSDATE);
  END IF;
END

http://hsqldb.org/doc/2.0/guide/sqlroutines-chapt.html#src_psm_conditional

于 2012-11-17T11:14:42.043 回答