Mutating Error in Triggers

I wrote a trigger which fires after inserting on an table.The aim of the trigger was, on some conditions of inserted data it should update the same record that was inserted.
It gives me an error stating that the trigger is MUTATING and fails to
execute.
I want to know whether we can update an record which is being inserted, thro an trigger.. if yes how or if no why?
it would be very helpfull for me if u can solve the above please give me an reply at my mail id.
Eagerly Waiting for an positive reply.
With Regards
Raghavendra
null

Raghavendra, this is probably a question for the SQL and PL/SQL group.
1) Can't you just modify the record directly (:NEW.column := whatever) in a BEFORE ROW trigger instead of an AFTER (ROW) trigger?
2) You can issue an UPDATE against the same row in an AFTER STATEMENT trigger, but take care to not cause recursion.

Similar Messages

  • How to solve mutating error

    i am getting mutating table error in triggers how to avoid this error

    Hi,
    You posted another question today in the SQL and PL/SQL forum, and that is also where you should have posted this:
    PL/SQL
    The SQL Developer (Not for general SQL/PLSQL questions) forum is only for questions regarding the SQL Developer tool. Please mark this as answered.
    Regards,
    Gary

  • How to over come mutating error

    Can Anyone explain me how to OVERCOME Mutating error when firing a trigger ?
    Thanks in advance.

    1. Don't use triggers
    2. Don't perform DML on the same table your trigger is based on.
    Without information (such as your table create statement and your trigger code) there's not a lot else we can say right now.
    If you're getting a mutating table error, it's an indication that either your logic or your design (or both!) need rethinking...

  • ME_PROCESS_PO_CUST allows save in ME21n  -  error message triggered

    All,
    Purchase order is getting saved even though there are error messages triggered via BADI in the POST method.
    I've tried both:
    MMPUR_MESSAGE_FORCED 'A' 'ME' '303' TEXT-001 '' '' '' .
    MMPUR_MESSAGE_FORCED 'E' 'ME' '303' TEXT-001 '' '' '' .
    Still the purchase order gets saved when the save button is clicked.
    Any ideas
    Meghna

    Hi Meghana,
    You can use method CHECK. I am using CHECK method and able to raise a error message.
    Sample code I am using is as follows:
    DATA i_items TYPE purchase_order_items.
      DATA: wa_item LIKE LINE OF i_items ,
      lv_if_item TYPE REF TO if_purchase_order_item_mm ,
      lt_itm_data TYPE mepoitem ,
      lv_table_count TYPE i .
    To get Header Data
      ls_header1 = im_header->get_data( ).
    To get item data
        CALL METHOD im_header->get_items
          RECEIVING
            re_items = i_items.
    Get actual line item data using Hask Key for line item
        READ TABLE i_items INTO wa_item INDEX 1.   --- you can use LOOP as per your requirement
        lv_if_item = wa_item-item.
        CALL METHOD lv_if_item->get_data
          RECEIVING
            re_data = lt_itm_data.
    IF ( v_result > 10000 ) .  " If the difference between net-prices is more than 10000 then gives Error message
            MESSAGE e368(00) WITH 'Tolerance is more than $10000' .
    ENDIF.           
    Let me know if you need further help.
    Thanks & Regards,
    Anil Salekar

  • How to avoid mutating error when insert or update record

    Hi ,
    I have one transaction table which is having some detail record under one transaction number, after the one transaction number is over by insert or update, i
    want to check the total amounts of one flag should be matched on same table if it is not then give error message. But i am getting mutating error on insert or update event trigger on statement level trigger on above table.
    Is there any other way to avoid mutating error to solve the above problem or some temp table concepts to be used. help me its urgent.
    Thanks in advance,
    Sachin Khaladkar
    Pune

    Sachin, here's as short of an example as I could come up with on the fly. The sample data is ficticious and for example only.
    Let's say I need to keep a table of items by category and my business rule states that the items in the table within each category must total to 100% at all times. So I want to insert rows and then make sure any category added sums to 100% or I will rollback the transation. I can't sum the rows in a row-level trigger because I'd have to query the table and it is mutating (in the middle of being changed by a transaction). Even if I could query it while it is mutating, there may be multiple rows in a category with not all yet inserted, so checking the sum after each row is not useful.
    So here I will create;
    1. the item table
    2. a package to hold my record collection (associative array) for the trigger code (the category is used as a key to the array; if I insert 3 rows for a given category, I only need to sum that category once, right?
    3. a before statement trigger to initialize the record collection (since package variables hang around for the entire database session, I need to clear the array before the start of every DML (INSERT in this case) statement against the item table)
    4. a before row trigger to collect categories being inserted
    5. an after statement trigger to validate my business rule
    I then insert some sample data so you can see how it works. Let me know if you have any questions about this.
    SQL> CREATE TABLE item_t
      2   (category  NUMBER(2)   NOT NULL
      3   ,item_code VARCHAR2(2) NOT NULL
      4   ,pct       NUMBER(3,2) NOT NULL);
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE trg_pkg IS
      2    TYPE t_item_typ IS TABLE OF item_t.category%TYPE
      3      INDEX BY PLS_INTEGER;
      4    t_item       t_item_typ;
      5    t_empty_item t_item_typ;
      6  END trg_pkg;
      7  /
    Package created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_bs_trg
      2    BEFORE INSERT
      3    ON item_t
      4  BEGIN
      5    DBMS_OUTPUT.put_line('Initializing...');
      6    trg_pkg.t_item := trg_pkg.t_empty_item;
      7  END item_bs_trg;
      8  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_br_trg
      2    BEFORE INSERT
      3    ON item_t
      4    FOR EACH ROW
      5  BEGIN
      6    trg_pkg.t_item(:NEW.category) := :NEW.category;
      7    DBMS_OUTPUT.put_line('Inserted Item for Category: '||:NEW.category);
      8  END item_br_trg;
      9  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_as_trg
      2    AFTER INSERT
      3    ON item_t
      4  DECLARE
      5    CURSOR c_item (cp_category item_t.category%TYPE) IS
      6      SELECT SUM(pct) pct
      7        FROM item_t
      8       WHERE category = cp_category;
      9  BEGIN
    10    DBMS_OUTPUT.put_line('Verifying...');
    11    FOR i IN trg_pkg.t_item.FIRST..trg_pkg.t_item.LAST LOOP
    12      DBMS_OUTPUT.put_line('Checking Category: '||trg_pkg.t_item(i));
    13      FOR rec IN c_item(trg_pkg.t_item(i)) LOOP
    14        IF rec.pct != 1 THEN
    15          RAISE_APPLICATION_ERROR(-20001,'Category '||trg_pkg.t_item(i)||' total = '||rec.pct);
    16        END IF;
    17      END LOOP;
    18    END LOOP;
    19  END item_as_trg;
    20  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL> INSERT INTO item_t
      2    SELECT 1, 'AA', .3 FROM DUAL
      3    UNION ALL
      4    SELECT 2, 'AB', .6 FROM DUAL
      5    UNION ALL
      6    SELECT 1, 'AC', .2 FROM DUAL
      7    UNION ALL
      8    SELECT 3, 'AA',  1 FROM DUAL
      9    UNION ALL
    10    SELECT 1, 'AA', .5 FROM DUAL
    11    UNION ALL
    12    SELECT 2, 'AB', .4 FROM DUAL;
    Initializing...
    Inserted Item for Category: 1
    Inserted Item for Category: 2
    Inserted Item for Category: 1
    Inserted Item for Category: 3
    Inserted Item for Category: 1
    Inserted Item for Category: 2
    Verifying...
    Checking Category: 1
    Checking Category: 2
    Checking Category: 3
    6 rows created.
    SQL>
    SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
      CATEGORY IT        PCT
             1 AA         .3
             1 AA         .5
             1 AC         .2
             2 AB         .4
             2 AB         .6
             3 AA          1
    6 rows selected.
    SQL>
    SQL> INSERT INTO item_t
      2    SELECT 4, 'AB', .5 FROM DUAL
      3    UNION ALL
      4    SELECT 5, 'AC', .2 FROM DUAL
      5    UNION ALL
      6    SELECT 5, 'AA', .5 FROM DUAL
      7    UNION ALL
      8    SELECT 4, 'AB', .5 FROM DUAL
      9    UNION ALL
    10    SELECT 4, 'AC', .4 FROM DUAL;
    Initializing...
    Inserted Item for Category: 4
    Inserted Item for Category: 5
    Inserted Item for Category: 5
    Inserted Item for Category: 4
    Inserted Item for Category: 4
    Verifying...
    Checking Category: 4
    INSERT INTO item_t
    ERROR at line 1:
    ORA-20001: Category 4 total = 1.4
    ORA-06512: at "PNOSKO.ITEM_AS_TRG", line 12
    ORA-04088: error during execution of trigger 'PNOSKO.ITEM_AS_TRG'
    SQL>
    SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
      CATEGORY IT        PCT
             1 AA         .3
             1 AA         .5
             1 AC         .2
             2 AB         .4
             2 AB         .6
             3 AA          1
    6 rows selected.
    SQL>

  • Mutation error

    Hi,
    I have form in which we are creating parent child relation .The table structure is as follows
    problems(table name)(prom_number,prom_relation,prom_impact,prom_relation,...)(column name).
    I dont have the forms fmb file ,So whenwe create the relation 2 update statement gets executed first in problem table the prom_number which is parent in its problem_relation column its assigned as parent and the problem which is chilld in its column value assigne dare (prom_relation,prom_prom_number)(child,and the value or pro_number which is parent).
    Now our requirement is that the value of prom_impact of child should be assigned to problem which is parent,So i have written a trigger which update the prom_impact column whcih gives mutation error.SO how can we solve this issue.

    The trigger i have written is given below.
    The problem is that from form level the table is updated twice and in the trigger i try to update the row which is parent fault .howere its show mutation error.I even created trigger which shall commit the when from problem_rlation is cahnged to parent .so that in my trigger wheh i update the column prom_imapct field in trigger there should be no reeor.Still it given mutation error.
    CREATE OR REPLACE TRIGGER parent_child_impact_trg
    AFTER UPDATE /*OF prom_relation,prom_prom_number*/ ON PROBLEMS
    REFERENCING NEW AS NEW
    FOR EACH ROW
    Version History:9.2.8.1
    (format: version, date, developer, description)
    1.0, 19-Dec-2008, Tanmoy Kr Moulik The "Impact" of Paren fault ticket
    will be changed upon manual creation of Parent Child relation
    Rules:
    1.0     Upon manual creation of new Parent-Child fault relation, the 'Fault Impact' of
    Child fault will be auto updated in the parent fault, if the parent fault impact matches
    with the attached list(Non Serve Affeect or Threat) or the impact of Parent Fault is blank (null).
    2.0     In case, the parent fault have fault impact matches with the attached list
    (service affect), then its impact is not changed while making the relationship.
    DECLARE
    PRAGMA autonomous_transaction;
    ecode NUMBER;
    emesg VARCHAR2(200);
    --BEGIN
    -- NULL;
    CURSOR c1--(v_prom_num NUMBER)
    IS
    SELECT PROM_IMPACT,prom_number FROM PROBLEMS WHERE prom_number=:NEW.prom_prom_number;
    v_prom_imp VARCHAR2(30) DEFAULT NULL;
    v_prom_imp_p1 NUMBER DEFAULT 0;
    v_prom_imp_p2 NUMBER DEFAULT 0;
    v_prom_num NUMBER;
    BEGIN
    IF :NEW.PROM_RELATION='CHILD' AND :NEW.PROM_PROM_NUMBER IS NOT NULL THEN
    --dbms_output.put_line(1);
    --INSERT INTO TEMP_PROM VALUES(:NEW.prom_number,:NEW.prom_prom_number,:NEW.prom_impact,:NEW.prom_relation);
    --COMMIT;
    OPEN c1;--(:NEW.prom_prom_number);
    FETCH c1 INTO v_prom_imp,v_prom_num;
    --INSERT INTO TEMP_PROM(PROM_NUM,PROM_IMPACT) VALUES(v_prom_num,v_prom_imp);
    --COMMIT;
    IF c1%NOTFOUND THEN
    v_prom_imp:=NULL;
    v_prom_num:=NULL;
    END IF;
    CLOSE c1;
    v_prom_imp:=UPPER(v_prom_imp);
    v_prom_imp_p1:=INSTR(v_prom_imp,'NON');
    v_prom_imp_p2:=INSTR(v_prom_imp,'THREAT');
    --INSERT INTO TEMP_PROM(PROM_NUM) VALUES(v_prom_imp_p1);
    --INSERT INTO TEMP_PROM(PROM_NUM) VALUES(v_prom_imp_p2);
    --COMMIT;
    IF v_prom_imp_p1>0 /*OR v_prom_imp_p2>0*/ THEN
    IF :NEW.prom_impact IS NOT NULL THEN
    BEGIN
    INSERT INTO TEMP_PROM(PROM_NUM,PROM_PROM_NUMBER,prom_impact,PROM_RELATION) VALUES(:NEW.prom_number,:NEW.prom_prom_number,:NEW.prom_impact,:NEW.prom_relation);
    COMMIT;
    EXCEPTION WHEN OTHERS THEN
    INSERT INTO TEMP_PROM(prom_impact,PROM_RELATION) VALUES('failed1'||ecode,emesg);
    END;
    BEGIN
    COMMIT;
    UPDATE PROBLEMS SET PROM_IMPACT=:NEW.PROM_IMPACT WHERE prom_number=:NEW.prom_prom_number;
    COMMIT;
    EXCEPTION WHEN OTHERS THEN
         ecode := SQLCODE;
    emesg := SQLERRM;
    -- BEGIN
    INSERT INTO TEMP_PROM(prom_impact,PROM_RELATION) VALUES('failed'||ecode,emesg);
    COMMIT;
    -- EXCEPTION WHEN OTHERS THEN*/
         NULL;
         --END;
    END;     
    END IF;     
         /*BEGIN
         INSERT INTO TEMP_PROM(PROM_NUM,PROM_IMPACT) VALUES(:NEW.prom_prom_number,:NEW.prom_impact);
         COMMIT;
    EXCEPTION WHEN OTHERS THEN
         INSERT INTO TEMP_PROM(prom_impact) VALUES('failed1');
         NULL;
         END;
    --NULL;
    -- END;
    --COMMIT;
    --END;
    /* BEGIN
    INSERT INTO TEMP_PROM(PROM_NUM,PROM_IMPACT) VALUES(:NEW.prom_prom_number,:NEW.prom_impact);
    EXCEPTION WHEN OTHERS THEN
    --INSERT INTO TEMP_PROM(prom_impact) VALUES('failed');
    NULL;
    END;
    COMMIT;
    --COMMIT;
    /* ELSIF v_prom_imp_p2>0 THEN
    -- v_prom_imp_p2
    IF :NEW.prom_impact IS NOT NULL THEN
    BEGIN
    UPDATE PROBLEMS SET PROM_IMPACT=:NEW.PROM_IMPACT WHERE prom_number=:NEW.prom_prom_number;
    EXCEPTION WHEN OTHERS THEN
    BEGIN
         ecode := SQLCODE;
    emesg := SQLERRM;
    --BEGIN
    INSERT INTO TEMP_PROM(prom_impact,PROM_RELATION) VALUES('failed'||ecode,emesg);
    COMMIT;
    --EXCEPTION WHEN OTHERS THEN
         NULL;
         END;
    NULL;
    END;
    COMMIT;
    BEGIN
    INSERT INTO TEMP_PROM(PROM_NUM,PROM_IMPACT) VALUES(:NEW.prom_prom_number,:NEW.prom_impact);
    EXCEPTION WHEN OTHERS THEN
    NULL;
    END;
    COMMIT;*/
    --UPDATE PROBLEMS SET PROM_IMPACT=:NEW.PROM_IMPACT WHERE prom_number=:NEW.prom_prom_number;
    -- COMMIT;
    -- END IF;
    END IF;
    END IF;
    EXCEPTION WHEN OTHERS THEN
    INSERT INTO TEMP_PROM(prom_impact,PROM_RELATION) VALUES('failed2'||ecode,emesg);
    COMMIT;
    NULL;
    END;

  • How to handle the mutating error

    create or replace trigger trg_t1
    after insert on t1
    begin
    insert into t1 values(1);
    end;
    i got some error..

    1011927 wrote:
    same table with the same trigger
    Within  trigger code do not issue SQL against same table upon which trigger is based; then no mutating error is thrown

  • URGENT : Trigger with Mutating Error

    Hi,
    I'm trying to write a trigger on a Table ROOM_BLOCK to update a value in table ROOM_OOI_OOS.
    As given below, which works perfectly.
    BEGIN
    IF INSERTING THEN
    IF NVL(:NEW.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)+1
    WHERE ROOM_OOI_OOS_ID = :NEW.ROOM_OOI_OOS_ID;
    END IF;
    ELSIF UPDATING THEN
    IF NVL(:OLD.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)-1
    WHERE ROOM_OOI_OOS_ID = :OLD.ROOM_OOI_OOS_ID;
    END IF;
    IF NVL(:NEW.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)+1
    WHERE ROOM_OOI_OOS_ID = :NEW.ROOM_OOI_OOS_ID;
    END IF;
    ELSE
    IF NVL(:OLD.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)-1
    WHERE ROOM_OOI_OOS_ID = :OLD.ROOM_OOI_OOS_ID;
    END IF;
    END IF;
    END;
    But when I add a select statement. the trigger seems to fail with a mutating error ORA-04091
    and Error at Line which executes the statement immidiate ORA-04088.
    DECLARE
    stmt VARCHAR2(500);
    vcount INTEGER;
    BEGIN
    IF INSERTING THEN
    --INSERT INTO SHRUTI_TEST (DESCR) VALUES ('Inserting');
    IF NVL(:NEW.ROOM_OOI_OOS_ID,0) <> 0 THEN
    stmt := 'Select count(*) from ROOM_BLOCK ' ||
    ' WHERE ROOM_OOI_OOS_ID = ' || :NEW.ROOM_OOI_OOS_ID ||
    ' AND ROOM_NO = ''' || :NEW.ROOM_NO || ''' ';
    EXECUTE IMMEDIATE stmt INTO vcount;
    IF vcount = 1 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)+1
    WHERE ROOM_OOI_OOS_ID = :NEW.ROOM_OOI_OOS_ID;
    END IF;
    END IF;
    ELSIF UPDATING THEN
    IF NVL(:OLD.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)-1
    WHERE ROOM_OOI_OOS_ID = :OLD.ROOM_OOI_OOS_ID;
    END IF;
    IF NVL(:NEW.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)+1
    WHERE ROOM_OOI_OOS_ID = :NEW.ROOM_OOI_OOS_ID;
    END IF;
    ELSE
    IF NVL(:OLD.ROOM_OOI_OOS_ID,0) <> 0 THEN
    UPDATE ROOM_OOI_OOS SET NO_OF_ROOMS = NVL(NO_OF_ROOMS,0)-1
    WHERE ROOM_OOI_OOS_ID = :OLD.ROOM_OOI_OOS_ID;
    END IF;
    END IF;
    END;
    Please tell me how to solve this problem...
    Regards
    Mike.

    Thank you for your reply to my posting.
    I researched and used your recommendation. I was
    wondering if you can help me resolve the following two
    problems.
    Table kassa1 has NAME and AGE columns. Table Kassa2
    has one column Age.
    I have created the following trigger. It keeps
    raising a ORA-06519 : Active autonomous transaction
    detected and rolled back error.
    Create or replace trigger Name_Age_Row after insert or
    update on Kassa1
    For each row
    Declare
    Total_Age VARCHAR(8);
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
         Select SUM(Age) into Total_Age from Kassa1;
         insert into kassa2 values(Total_aAge);
    End;     
    The following trigger also generates ORA-00036:
    Maximum number of recursive SQL levels(50) exceeded
    error.
    Create or replace trigger Name_Age_Row after insert or
    update on Kassa1
    For each row
    Declare
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
         insert into kassa1 values('newname', 'newage');
    End;     

  • A SMALL EXAMPLE CODE FOR MUTATING ERROR

    create or replace trigger TRG_T1
    before insert on T1
    begin
    insert into T1 values(2);
    end;
    IF I TRY TO INSERT INTO T1 TABLE I GET A MUTATING ERROR HOW CAN I SOLVE??????

    joealexander wrote:
    create or replace trigger TRG_T1
    before insert on T1
    begin
    insert into T1 values(2);
    end;
    IF I TRY TO INSERT INTO T1 TABLE I GET A MUTATING ERROR HOW CAN I SOLVE??????
    No, you do NOT get a mutating table error. You get this:
    orcl112> create table t1(c1 number);
    Table created.
    Elapsed: 00:00:00.03
    orcl112> create or replace trigger TRG_T1
      2
      3  before insert on T1
      4
      5  begin
      6
      7  insert into T1 values(2);
      8
      9  end;
    10
    11  /
    Trigger created.
    Elapsed: 00:00:00.04
    orcl112> insert into t1 values (1);
    insert into t1 values (1)
    ERROR at line 1:
    ORA-00036: maximum number of recursive SQL levels (50) exceeded
    ORA-06512: at "SCOTT.TRG_T1", line 3
    ORA-04088: error during execution of trigger 'SCOTT.TRG_T1'
    ORA-06512: at "SCOTT.TRG_T1", line 3
    ORA-04088: error during execution of trigger 'SCOTT.TRG_T1'
    ORA-06512: at "SCOTT.TRG_T1", line 3
    ORA-04088: error during execution of trigger 'SCOTT.TRG_T1'
    ORA-06512: at "SCOTT.TRG_T1", line 3
    ORA-04088: error during execution of trigger 'SCOTT.TRG_T1'
    ORA-06512: at "SCOTT.TRG_T1", line 3
    ORA-04088: error during execution of trigger 'SCOTT.TRG_T1'
    You are the second person today who has claimed to have seen this error and posted code that did not raise it. What is going on?

  • Mutating error solution

    hi group
    prem here
    i am stillnot able to get the solution for mutating error.
    let me give u scenario
    before insert trigger -----on emp and in the trigger i select using the :new values , i get the mutating error,fine so far so good.
    when it comes to solution i am unable tomake out from the link which was given in one of the replies,
    can anyone pls in a simple words try to give a solution for:::::
    scenario before i insert into emp a record i need to check if there is no record present in the table
    solution ----
    after going thru few sites i could zero in to a simple solution
    1.creat a package variable store the :new variable
    2.create a procedure or function to test if record exists and pass yesy or no to the trigger and then take the decision
    also under what other cases do we get mutating errors
    pls look into this problem and give me a solution
    i hope it wll be of gr8 help to thers also
    regards
    prem

    http://asktom.oracle.com/pls/ask/f?p=4950:8:14402737568889680009::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:469621337269
    Rgds.

  • Mutating error in different situations....

    Hi All
    I am getting mutating error in the following situtations.......please provide the suitable solution
    1) Update same table on which trigger has been written
    e.g. written trigger on abc table in which
    command
    update abc set col_nm=’New Name’
    where col_id=
    2) In trigger block called some procedure.
    In procedure again update same table.
    e.g. written trigger on abc table
    it calls proc1 procedure.
    In proc1 procedure it again update abc table
    3)Select same table in same trigger e.g.
    Written trigger on abc table and in that again query for selecting data.
    Select sum(col_1) from abc
    4)In trigger block called some procedure.
    In procedure again select same table.
    e.g. written trigger on abc table
    it calls proc1 procedure.
    In proc1 procedure it again select sum(col_1) from abc
    5) In trigger block called some procedure in procedure update
    another table which has a trigger in this trigger there is update or select query
    for same table
    e.g written trigger on abc table it calls procedure proc1 in proc1 it is updating some other table
    xyz which has a update trigger in this update trigger it has updating and selecting data from
    table abc.

    http://asktom.oracle.com/tkyte/Mutate/index.html

  • Mutating error in my trigger code

    Hi,
    Could anyone please help me out to fix the mutating error:
    I have 2 tables z_errorpayment and z_errorcorrected.
    If the status=2 in z_errorpayment table then a row has to be inserted in z_errorcorrected table and the same row has to be deleted from the 1st table i.e z_errorpayment.As it is retriving from the same table and deleting the same table am getting mutating error.
    Below is the code.
    CREATE OR REPLACE TRIGGER row_trigger
    AFTER UPDATE
    ON z_errorpayment
    FOR EACH ROW
    WHEN (NEW.status = 2)
    BEGIN
    INSERT INTO z_errorcorrected
    (mtnl_error_payment_id, file_name, entry_date,
    centre_code, service_code, instrument_flag,
    instrument_no, subs_no, instrument_dt,
    payment_mode, payment_dt, surchrg,
    telephone_no, cheque_number, cheque_dt,
    bank_code, pay_amount, receipt_no,
    terminal_id, crtn_by, crtn_dt, remarks,
    status, external_trans_id, transfer_date,
    gl_uploaded_ind_code, task_queue_id,
    user_name, old_payment_id, new_payment_id,
    payment_type
    VALUES (:NEW.mtnl_error_payment_id, :NEW.file_name, :NEW.entry_date,
    :NEW.centre_code, :NEW.service_code, :NEW.instrument_flag,
    :NEW.instrument_no, :NEW.subs_no, :NEW.instrument_dt,
    :NEW.payment_mode, :NEW.payment_dt, :NEW.surchrg,
    :NEW.telephone_no, :NEW.cheque_number, :NEW.cheque_dt,
    :NEW.bank_code, :NEW.pay_amount, :NEW.receipt_no,
    :NEW.terminal_id, :NEW.crtn_by, :NEW.crtn_dt, :NEW.remarks,
    :NEW.status, :NEW.external_trans_id, :NEW.transfer_date,
    :NEW.gl_uploaded_ind_code, :NEW.task_queue_id,
    :NEW.user_name, :NEW.old_payment_id, :NEW.new_payment_id,
    :NEW.payment_type
    DELETE FROM z_errorpayment
    WHERE new_payment_id = :NEW.new_payment_id;
    END;
    so I thought of using a view inorder to get rid of the mutating error.
    But donno how to code it.
    could anyone please help me out.
    Regards,
    Rupa

    By using a view i wrote the below code:
    CREATE OR REPLACE TRIGGER row_trigger
    INSTEAD OF UPDATE
    ON Z_ErrorView
    FOR EACH ROW
    DECLARE
    X INTEGER;
    BEGIN
    SELECT STATUS into X FROM z_errorpayment WHERE new_payment_id = :NEW.new_payment_id;
    IF X=2 THEN
    INSERT INTO z_errorcorrected
    (mtnl_error_payment_id, file_name, entry_date,
    centre_code, service_code, instrument_flag,
    instrument_no, subs_no, instrument_dt,
    payment_mode, payment_dt, surchrg,
    telephone_no, cheque_number, cheque_dt,
    bank_code, pay_amount, receipt_no,
    terminal_id, crtn_by, crtn_dt, remarks,
    status, external_trans_id, transfer_date,
    gl_uploaded_ind_code, task_queue_id,
    user_name, old_payment_id, new_payment_id,
    payment_type
    VALUES (:NEW.mtnl_error_payment_id, :NEW.file_name, :NEW.entry_date,
    :NEW.centre_code, :NEW.service_code, :NEW.instrument_flag,
    :NEW.instrument_no, :NEW.subs_no, :NEW.instrument_dt,
    :NEW.payment_mode, :NEW.payment_dt, :NEW.surchrg,
    :NEW.telephone_no, :NEW.cheque_number, :NEW.cheque_dt,
    :NEW.bank_code, :NEW.pay_amount, :NEW.receipt_no,
    :NEW.terminal_id, :NEW.crtn_by, :NEW.crtn_dt, :NEW.remarks,
    :NEW.status, :NEW.external_trans_id, :NEW.transfer_date,
    :NEW.gl_uploaded_ind_code, :NEW.task_queue_id,
    :NEW.user_name, :NEW.old_payment_id, :NEW.new_payment_id,
    :NEW.payment_type
         END IF;
    DELETE FROM z_errorpayment
    WHERE new_payment_id = :NEW.new_payment_id;
    END;

  • Mutating error in trigger

    Hi ,ihave created this trigger.its showing the mutating error as its selecting and updating the same table.So hw can we modify thsi trigger so that it worksd properly.
    CREATE OR REPLACE TRIGGER resolutionimpact
    AFTER INSERT OR UPDATE
    ON PROBLEMS
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    newcause VARCHAR2(100);
    oldcause VARCHAR2(10);
    BEGIN
    oldcause:=:OLD.PROM_NCCCAUSE;
    newcause:=:NEW.PROM_NCCCAUSE;
    IF newcause='100' THEN
    UPDATE PROBLEMS SET PROM_IMPACT='CA_TCL FLP reset';
    --PROM_IMPACT='CA_TCL FLP reset';
    END IF;
    END;

    No actually I am udating single row.Actually the value is being entered from the oracle form from front end and no matter whatever value we enter for prom_impact from front end it should overwrite that value with fixed value when we press the save button .Also we cannot do anything at form level as we have fmx and nt the fmb.So have to do it through trigger only.Also there is another trigger running on same table which fetches the value from problem table and inserts it into another table.So what can be done to solve the issue

  • Mutating error -oracle version 8i

    I have a problem of mutating error in Oracle.If u have any solution kindly forward it to me.
    I have a table e1 as shown below:
    SQL>select * from e1;
    code id transdate destination
    The trigger is to fire after insert of a row
    when "id" is 2.
    The trigger calls a procedure which calculates a new
    "transdate" and inserts a new record into the table e1 with
    the newly calculated "transdate","id" as 12 and all the other
    columns(code and destination)remains the same.
    I have to pass "code" and "transdate" as input parameters to the
    procedure.
    Inside the procedure i have a select statement which fetches
    the record from table e1(which is being inserted and fires a trigger).
    This is the rootcause of the problem.
    Since the trigger is firing after Insert,looping
    happens and hence gives out the same error.
    I even tried to use the PRAGMA AUTONOMOUS_TRANSACTION but it is not
    supported in our version.
    Please let me know if there is some other alternate to this.
    --Regards,
    Arthi

    http://osi.oracle.com/~tkyte/Mutate/index.html

  • Help with Mutating Error / Trigger / APEX_MAIL.SEND

    Hello:
    I am trying to get the apex_mail.send function working when a user submits a new record. I've taken the code from the canned Issue Tracker application code and tried to retrofit it to my tables. However I keep receiving a mutating error on line 11 (line 11 bolded below):
    -- Create a trigger that will send notification after
    -- the submission of each new idea on the IDEAS table.
    create or replace trigger IDEAS_EMAIL
    AFTER
    insert or update on IDEAS
    for each row
    begin
    IF (INSERTING AND :new.manager_name IS NOT NULL)
    OR
    (UPDATING AND (:old.manager_name IS NULL OR :new.manager_name != :old.manager_name) AND :new.manager_name IS NOT NULL) THEN
    FOR c1 IN
    (SELECT fname, lname, email
    FROM ideas_users
    WHERE fname||' '||lname = :new.manager_name)
    LOOP
    IF c1.email IS NOT NULL THEN
    FOR c2 IN
    (SELECT MANAGER_NAME, FULL_TEXT, SUMMARY, ID, SUBMITTED_BY, SUB_DATE
    FROM IDEAS
    WHERE ID = :new.ID)
    LOOP
    APEX_MAIL.SEND(
    p_to => c1.email,
    p_from => c1.email,
    p_body =>
    'This is a test message. ' ||chr(10)||
    p_subj => 'test email subject');
    END LOOP;
    END IF;
    END LOOP;
    END IF;
    end;
    I've also tried setting the following line to the primary key field in the user table and inserting that value into the main table but I still get the same error message.
    WHERE fname||' '||lname = :new.manager_name)
    Thanks in advance for any help.

    Let me get this straight..
    You are inserting a row into a table, and when you insert the row, you are going to send an e-mail t o the manager who owns this row. In the data you are inserting, is the e-mail address of the manager, right?
    David has provided the answer for you.. Use the :NEW.Email value instead of creating a cursor and all that.. Unless you have a need to e-mail multiple people of the record insert..
    Thank you,
    Tony Miller
    Webster, TX
    On the road of life...There are 'windshields', and there are 'bugs'
    (splat!)
    "Squeegees Wanted"

Maybe you are looking for

  • Material to be produce included in production order component review

    Hello gurus, i have a issue about production order. 1. The BOM of XXXX material have the next components:     A     B     C 2. When i create a production order for 100 ST of  XXX material, the component review in production order includes the next:  

  • Unable to install aperture 3.1 dvd on snow leopard or lion

    I have an aperture 3.1 install DVD.  I tried to install it on my macbook running lion 10.7.3 and it says: I then tried to install it on my mac mini running snow leopard 10.6.8... same result. Then I tried to install on my macbook (dual booted with th

  • I'm due for a new phone, looking at the E63

    The issue I have is I am hearing impaired and struggle to find a phone with a tone I can hear well. I hear low tones quite well if the volume is cranked up but most of the custom tones I can't hear as they are too much in the high range which I can't

  • Credit card charged despite of a free account

    My credit card was charged for 30.74 € twice this month despite the only order on my account being a FREE creative cloud subscription. I'm wondering if I have created another account for another e-mail and have forgotten and it is now charging me for

  • PROTOCOL_ERROR line 627 of URL.cpp unexpected EOF reading HTTP status

    Hello, I'm having a problem getting the NSAPI plugin talking with the WLS6.1sp3 Application server. The iPlanet Server logs the error: *******Exception type [PROTOCOL_ERROR] raised at line 627 of URL.cpp Thu Oct 31 10:20:03 2002 got exception in send