具有多个when子句的HSQL触发器

时间:2012-11-17 04:21:27

标签: triggers hsqldb clause

我们可以在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) )
;

此查询提供语法错误。 什么是正确的语法?

1 个答案:

答案 0 :(得分: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