2017-01-25 54 views
0
CREATE OR REPLACE TRIGGER Testtriger 
    after insert ON table2 referencing new as new old as old 
    for each row 
declare 
    flagtemp varchar2(1); 
begin 
    select flag into flagtemp from table2 where docid = :new.docid; 
    --if :new.cardtypeflag = 'T' then 
    update table1 set col1 = 'F' , col2= 'T', inactive = 'T', col3 = 'T' 
    where tabid = :new.docid; 
    --end if; 
end; 
/

此觸發器給出了突變錯誤,請幫助解決它。Oracle觸發器重合錯誤

+0

http://dba.stackexchange.com/questions/5432/what-are-the-causes-and-solutions-for-mutating-table-errors – GurV

+0

[ORACLE可能重複更新後觸發器:解決ORA-04091突變表錯誤](http://stackoverflow.com/questions/6915325/oracle-after-update-trigger-solving-ora-04091-mutating-table-error) –

回答

1

你的觸發器包含對具有觸發器的表執行的選擇:

select flag into flagtemp from table2 where docid = :new.docid; 

Oracle數據庫操作需要可預測的狀態。此選擇的結果是不可預測的,因爲您處於交易中期:數據尚未應用。所以觸發器會因爲突變錯誤而失敗。

在這種情況下,似乎所有你需要做的是

flagtemp := :new.flag; 

,或者甚至更好,破除分配,如你不觸發的其餘部分使用局部變量。