Oracle触发器不允许表

时间:2015-10-27 13:46:03

标签: sql oracle triggers

"插入" oracle触发器会停止满足特定条件的任何插入。触发器正在检查列" CLASS_TIME"如果它小于上午9点或大于下午6点,则更新插入的行。但是没有完全插入行,因此无法更新同一行。以下是触发代码

create or replace TRIGGER ENFORCE_CLASS_TIMINGS 
AFTER INSERT ON SYSTEM.TUTPRAC 
REFERENCING OLD AS OLD1 NEW AS NEW1
FOR EACH ROW
WHEN ( 
  to_number(to_char(to_date(NEW1.CLASS_TIME,'hh24:mi'),'sssss')) < 
    to_number(to_char(to_date('09:00', 'hh24:mi'), 'sssss')) OR
  to_number(to_char(to_date(NEW1.CLASS_TIME,'hh24:mi'),'sssss')) > 
    to_number(to_char(to_date('18:00', 'hh24:mi'), 'sssss')))

BEGIN

  UPDATE SYSTEM.TUTPRAC
    SET STAFFNO = NULL
  WHERE
    CLASSID = :NEW1.CLASSID;

    COMMIT;
END;

请建议如何修复它。

1 个答案:

答案 0 :(得分:1)

试试这个(我删除了REFERENCING OLD作为OLD1,因为它在插入触发器中没有意义):

create or replace TRIGGER ENFORCE_CLASS_TIMINGS 
BEFORE INSERT ON SYSTEM.TUTPRAC 
REFERENCING NEW AS NEW1
FOR EACH ROW
WHEN ( 
  to_number(to_char(to_date(:NEW1.CLASS_TIME,'hh24:mi'),'sssss')) < 
    to_number(to_char(to_date('09:00', 'hh24:mi'), 'sssss')) OR
  to_number(to_char(to_date(:NEW1.CLASS_TIME,'hh24:mi'),'sssss')) > 
    to_number(to_char(to_date('18:00', 'hh24:mi'), 'sssss')))

BEGIN
  :NEW1.STAFFNO := NULL;
END;