触发触发时突变表错误

时间:2016-12-06 23:08:11

标签: database oracle triggers

触发此触发器时收到错误ORA-04091:

    CREATE OR REPLACE TRIGGER SendNotifications 
       AFTER UPDATE OF penalty_amount ON Penalites
       FOR EACH ROW
   DECLARE
      phone_no number(9,0);
       BEGIN  
          SELECT PHONE_NUMBER INTO phone_no
            FROM ADRESSES
            INNER JOIN ORDERS
              ON adresses.ID_READER = orders.ID_READER
            INNER JOIN PENALITES
              ON orders.ID_ORDER = penalites.ID_ORDER
          WHERE :new.ISPAID = 'N';

          DBMS_OUTPUT.PUT_LINE('Phone numbers where selected.');
       END;
    /

我想我应该使用:new。和:老。但我不知道如何处理它。你能给我任何建议或起点吗?

1 个答案:

答案 0 :(得分:0)

触发器中的SELECT语句正在尝试从PENALTIES检索数据,该表是定义触发器的表。不允许这样的行触发器从定义它们的表中检索数据。您有三种选择:

  1. 删除FOR EACH ROW
  2. ,使其成为语句触发器
  3. 从SELECT语句中删除PENALTIES。看来这个陈述会做同等的事情:

    SELECT PHONE_NUMBER FROM ADRESSES INNER JOIN ORDERS ON adresses.ID_READER = orders.ID_READER WHERE :new.ISPAID = 'N' AND orders.ID_ORDER = :new.ID_ORDER;

  4. 将此转换为复合触发器。 See this answer for details

  5. 祝你好运。