我不知道代码如何引发错误。它正确编译但在使用它时会引发错误。
create or replace TRIGGER TRG_APPLICATIONS
BEFORE INSERT or UPDATE OF APP_ID, STATUS_ID
ON APPLICATIONS
FOR EACH ROW
BEGIN
:new.APP_ID := SEQ_APP_ID.nextval;
:new.APP_DATE := SYSDATE;
IF UPDATING AND ( :NEW.STATUS_ID = 2 OR :NEW.STATUS_ID = 5 OR :NEW.STATUS_ID = 7 OR :NEW.STATUS_ID = 8 )
THEN
INSERT INTO APP_HISTORY (SRN, STATUS_ID, APP_DATE)
VALUES (:OLD.SRN, :OLD.STATUS_ID, :OLD.APP_DATE);
DELETE FROM APPLICATIONS WHERE :NEW.STATUS_ID = 2;
DELETE FROM APPLICATIONS WHERE :NEW.STATUS_ID = 5;
DELETE FROM APPLICATIONS WHERE :NEW.STATUS_ID = 7;
DELETE FROM APPLICATIONS WHERE :NEW.STATUS_ID = 8;
END IF;
END;
这是错误消息
error ORA-04091: table APEX514.APPLICATIONS is mutating,
trigger/function may not see it ORA-06512: at "APEX514.TRG_APPLICATIONS",
line 14 ORA-04088: error during execution of trigger 'APEX514.TRG_APPLICATIONS'
答案 0 :(得分:1)
变异表错误的最可能原因是滥用触发器。这是一个典型的例子: 1.你在表A中插入一行
2.表A上的触发器(对于每一行)在表A上执行查询,例如计算汇总列
3.Oracle抛出一个ORA-04091:表A正在变异,触发器/函数可能看不到它