Mutating error on after insert trigger

前端 未结 2 1789
无人及你
无人及你 2021-01-22 05:58

The below code is giving a mutating error. Can any1 pls help in solving this.

    CREATE OR REPLACE TRIGGER aso_quote_cuhk_trigger
    BEFORE INSERT
    ON aso.a         


        
2条回答
  •  深忆病人
    2021-01-22 06:33

    I realise you must have resolved your issue by now. However I am adding this answer below to help anyone else facing similar problem as you and I faced.

    I recently encountered mutating table (ORA-04091: table XXXX is mutating, trigger/function may not see it) issue and after searching around realised the Compound Triggers feature available in 11g. If you're on 11g following compound trigger would have solved your issue.

    CREATE OR REPLACE TRIGGER aso_quote_cuhk_trigger
    FOR INSERT ON aso.aso_quote_headers_all
    COMPOUND TRIGGER
    
        row_id    rowid;
    
        AFTER EACH ROW IS
        BEGIN
          row_id := :new.rowid;
        END AFTER EACH ROW;
    
        AFTER STATEMENT IS
        BEGIN
          UPDATE aso.aso_quote_headers_all 
          SET quote_expiration_date = sysdate+90 
          WHERE rowid = row_id;
        END AFTER STATEMENT;
    END aso_quote_cuhk_trigger;
    /
    

    A word about how it works. This compound trigger fires 2 events :

    1. First is AFTER EACH ROW where we capture the rowid of newly inserted row
    2. Next is AFTER STATEMENT where we update the table using rowid (captured during first event) in the WHERE clause.

    A useful link if you want to read more about Compound Triggers.

提交回复
热议问题