图1:trigger的触发顺序
上图1非常重要,对于trigger的触发顺序的解释一目了然,尤其是下半副图,update数据的时候,对于statement trigger,不管是before还是after,都只会执行一次,而row trigger,却会在每次的udpate的前后执行一次。
1、before、after触发器
创建statement trigger和row trigger的语法直接看下面代码:

-- statement级before trigger
CREATEORREPLACETRIGGERsecure_emp
BEFOREINSERTORDELETEORUPDATEONemployees
BEGIN
IF (TO_CHAR(SYSDATE,'DY')IN('SAT','SUN'))OR
(TO_CHAR(SYSDATE,'HH24:MI')NOTBETWEEN'08:00'AND'18:00')THEN
RAISE_APPLICATION_ERROR(-20500,
'You may modify EMPLOYEES table only on weekdays.');