0

次のようなトリガーがあります:(基本的に、テーブル1の列の更新時に、テーブル2の列を更新します)

CREATE OR REPLACE TRIGGER AAA   AFTER UPDATE 
   ON TABLE_1    REFERENCING NEW AS NEWROW OLD AS OLDROW
   FOR EACH ROW
WHEN (
NEWROW.DELETED ='Y' AND NEWROW.ID IN (41,43)
AND OLDROW.DELETED = 'N'
      )
DECLARE
id_1 number;
id_2 number;
id_3 number;
BEGIN

select id_1, id_2,id_3 into id_1,id_2,id_3  from  table_1 where id_1 = :NEWROW.id1 and id2 = some_other_row.id2;
if id_1 is  null
then

 update table2 set deleted = 'Y' ,   where table2.id_1 = id_1 and table2.id_2=id_2 and table2.id_3 = id_3;

   end if;

EXCEPTION
   WHEN OTHERS
   THEN
      -- Consider logging the error and then re-raise
      RAISE;
END AAA;
/

table1 を更新すると、次のようになります。

ORA-04091: table table1 is mutating, trigger/function may not see it 

このエラーは、トリガーが何かを更新しようとしているテーブルを更新しているときにのみ発生すると思いました。しかし、ここではtable1を更新しており、トリガーはtable2を更新することになっています。SOなぜエラーですか?

4

1 に答える 1