ORA-04091 (table string.string is mutating) and Function-Based Index

I've encountered a problem with DELETEing from a table when that table has a function-based index on it. The following demonstrates this:
SQL> CREATE OR REPLACE FUNCTION get_employee_location(p_empno IN number)
  2  RETURN varchar2
  3  DETERMINISTIC
  4  IS
  5  l_return_value   varchar2(20);
  6  BEGIN
  7  SELECT loc
  8  INTO   l_return_value
  9  FROM   dept
10  WHERE  deptno = (SELECT
11                   e.deptno
12                   FROM emp e
13                   WHERE empno = p_empno);
14  return l_return_value;
15  end;
16  /
Function created.
SQL> create index location_idx on emp (get_employee_location(empno));
Index created.
SQL> delete from emp;
delete from emp
ERROR at line 1:
ORA-04091: table SCOTT.EMP is mutating, trigger/function may not see it
ORA-06512: at "SCOTT.GET_EMPLOYEE_LOCATION", line 7------------------------------------------------
The question is: How can I successfully DELETE FROM emp but keep my function-based index in place?
Thanks
Andy

'Being able to' is 'being able to', but
it is dangerous to declare "DETERMINISTIC" for non-deterministic function.
The following problem happens on non-deterministic function index.
SQL> update dept set loc = 'NEWYORK' where deptno=10;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from emp where get_employee_location(deptno)='NEWYORK';
no rows selected
SQL> select * from dept;
    DEPTNO DNAME          LOC
        10 ACCOUNTING     NEWYORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON
SQL> select empno,ename from emp where get_employee_location(deptno)='NEW YORK';
     EMPNO ENAME
      7782 CLARK
      7839 KING
      7934 MILLER
SQL> select empno,ename,get_employee_location(deptno) from emp where deptno=10;
     EMPNO ENAME      GET_EMPLOYEE_LOCATION(DEPTNO)
      7782 CLARK
      7839 KING
      7934 MILLER
SQL> select empno,ename,get_employee_location(deptno) from emp where get_employee_location(deptno)='NEW YORK';
     EMPNO ENAME      GET_EMPLOYEE_LOCATION(DEPTNO)
      7782 CLARK      NEW YORK
      7839 KING       NEW YORK
      7934 MILLER     NEW YORK
SQL> drop index location_idx ;
Index dropped.
SQL> select empno,ename from emp where get_employee_location(deptno)='NEW YORK';
no rows selected

Similar Messages

  • ORA-04091: table ...is mutating, trigger/function may

    when I run a delete on this table I have the error
    ORA-04091: table MICRODEV.T086_LIEN_INSC is mutating, trigger/function may not see it
    ORA-06512: at "MICRODEV.TG_DEL_T086_LIEN_INSC", line 5
    ORA-04088: error during execution of trigger 'MICRODEV.TG_DEL_T086_LIEN_INSC'
    How Can I workaround it
    CREATE OR REPLACE TRIGGER "MICRODEV"."TG_DEL_T086_LIEN_INSC"
    BEFORE
    DELETE ON "MICRODEV"."T086_LIEN_INSC" FOR EACH ROW DECLARE lNbRows NUMBER(1);
    BEGIN
    IF :OLD.CO_PART_DNOM_SOC = 'DS' THEN
    SELECT 1 INTO lNbRows
    FROM T086_LIEN_INSC
    WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
    AND NO_INSC = :OLD.NO_INSC
    AND CO_PART_DNOM_SOC <> 'PA';
    IF lNbRows = 1 THEN
    raise_application_error(-20100, 'TRIGGER On Delete (T086_LIEN_INSC)');
    END IF;
    SELECT 2 INTO lNbRows
    FROM T086_LIEN_INSC
    WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
    AND NO_INSC = :OLD.NO_INSC
    AND CO_PART_DNOM_SOC = 'PA';
    IF lNbRows = 2 THEN
    raise_application_error(-20101, 'TRIGGER On Delete (T086_LIEN_INSC)');
    END IF;
    END IF;
    END;

    when I run a delete on this table I have the error
    ORA-04091: table MICRODEV.T086_LIEN_INSC is mutating, trigger/function may not see it
    ORA-06512: at "MICRODEV.TG_DEL_T086_LIEN_INSC", line 5
    ORA-04088: error during execution of trigger 'MICRODEV.TG_DEL_T086_LIEN_INSC'
    How Can I workaround it
    CREATE OR REPLACE TRIGGER "MICRODEV"."TG_DEL_T086_LIEN_INSC"
    BEFORE
    DELETE ON "MICRODEV"."T086_LIEN_INSC" FOR EACH ROW DECLARE lNbRows NUMBER(1);
    BEGIN
    IF :OLD.CO_PART_DNOM_SOC = 'DS' THEN
    SELECT 1 INTO lNbRows
    FROM T086_LIEN_INSC
    WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
    AND NO_INSC = :OLD.NO_INSC
    AND CO_PART_DNOM_SOC <> 'PA';
    IF lNbRows = 1 THEN
    raise_application_error(-20100, 'TRIGGER On Delete (T086_LIEN_INSC)');
    END IF;
    SELECT 2 INTO lNbRows
    FROM T086_LIEN_INSC
    WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
    AND NO_INSC = :OLD.NO_INSC
    AND CO_PART_DNOM_SOC = 'PA';
    IF lNbRows = 2 THEN
    raise_application_error(-20101, 'TRIGGER On Delete (T086_LIEN_INSC)');
    END IF;
    END IF;
    END;

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

    Hi,
    I keep getting this error message for my trigger when performing an
    insert..select statement (standard plain old insert works):
    ORA-04091: table ... is mutating, trigger/function may not see it
    The trigger is as follows:
    CREATE OR REPLACE TRIGGER MYTABLE_BEF_INS_CHECK
    BEFORE INSERT ON MYTABLE
    DECLARE
    v_o_id number(10);
    BEGIN
    IF :new.TYP = 'O' THEN
    SELECT 1
         INTO v_o_id
         FROM MYTABLE WHERE TYP = 'O' AND ID=:new.ID;
    END IF;
    END;
    The thing is the trigger works fine for a standard insert like:
    insert into MYTABLE( id,typ)
    values(426672,'O')
    No problem the above works. But when I try an insert select..it
    fails.
    insert into MYTABLE( id,typ)
    SELECT x_id, 'O' from AnyOtherTable;
    the above will fail.
    Anyone an idea why this is the case??
    thx.

    Hi,
    OK OK !!!! This was a copy/paste error. FOR EACH ROW was just not pasted here. Full trigger again:
    CREATE OR REPLACE TRIGGER MYTABLE_BEF_INS_CHECK
    BEFORE INSERT ON MYTABLE
    for each row
    DECLARE
    v_o_id number(10);
    BEGIN
    IF :new.TYP = 'O' THEN
    SELECT 1
         INTO v_o_id
         FROM MYTABLE WHERE TYP = 'O' AND ID=:new.ID;
    END IF;
    END;
    But I want to know why I DO NOT get this problem with the standard insert statement but only with the insert...select.
    thx.
    S.

  • ORA-04091: table CCS.T_PROCESSLOG is mutating, trigger/function may not see it

    I have a problem. Here is a trigger that I'm working with.
    CREATE OR REPLACE TRIGGER Trgedw_extract
    AFTER INSERT OR UPDATE OF completioncode ON CCS.t_processlog
    FOR EACH ROW
    WHEN ( (OLD.filename = 'ACCTINFO') AND (OLD.completioncode = 1) )
    BEGIN
    CCS.Edwextract;
    END;The t_processlog table has a field (processid) that is the primary key. However the processid wasn't setup as a sequence number directly through Oracle. It was set up as a sequence number through a trigger. (Don't ask...)
    The code for the procedure that the code above call is here.
    CREATE OR REPLACE PROCEDURE Edwextract AS
    Jobname: Edwextract
    Author: Adam Bolduc
    Date: 6/18/2001
    Purpose: To run the monthly jobs (ccs.populateedw92, ccs.populateedw54) to
    populate the t_edw table and export the data to a flat file on the system.
    This file will be sent to edw. Then drop and recreate the index on the t_edw table
    to access the data faster.
    EDW92 EXCEPTION;
    EDW54 EXCEPTION;
    PUTLINE_ERROR EXCEPTION;
    FILE_OPEN_ERROR EXCEPTION;
    FILE_CLOSE_ERROR EXCEPTION;
    DROP_INDEX_FLAG EXCEPTION;
    CREATE_INDEX_FLAG EXCEPTION;
    dPid ccs.t_processlog.PROCESSID%TYPE;
    szdata_rec CHAR(1436);
    outfile_name VARCHAR2(50) DEFAULT 'edw.txt';
    outfile_dir VARCHAR2(100) DEFAULT '/scratch/edw/';
    outfile_handle UTL_FILE.file_type;
    szSQLErrText VARCHAR2(250);
    iRetValue PLS_INTEGER;
    icursor_name INTEGER;
    irows_processed INTEGER;
    dtDateProcess ccs.t_processlog.PROCESSDATE%TYPE;
    CURSOR edw_extract_cur IS
    SELECT
    ccs.t_edw.RECORDIDENTIFIER&#0124; &#0124;
    ccs.t_edw.TSYSVERSIONINDICATOR&#0124; &#0124;
    ccs.t_edw.TS1CREDITRATING&#0124; &#0124;
    ccs.t_edw.TS1BILLINGTYPE&#0124; &#0124;
    ccs.t_edw.TS1PROCESSTYPE&#0124; &#0124;
    ccs.t_edw.TS1BANKNUMBER&#0124; &#0124;
    ccs.t_edw.TS1AGENTBANKNUMBER&#0124; &#0124;
    ccs.t_edw.PRODUCTCODE&#0124; &#0124;
    ccs.t_edw.CLIENTPRODUCTCODE&#0124; &#0124;
    ccs.t_edw.TRACKINGNUMBER&#0124; &#0124;
    ccs.edwaccountencrypt(ccs.t_edw.ACCOUNTNUMBER)&#0124; &#0124;
    ' '&#0124; &#0124;
    ccs.t_edw.NAMEPRIMARY&#0124; &#0124;
    ccs.t_edw.NAMECOAPP&#0124; &#0124;
    ccs.t_edw.ADDRESSLINE1&#0124; &#0124;
    ccs.t_edw.ADDRESSLINE2&#0124; &#0124;
    ccs.t_edw.CITY&#0124; &#0124;
    ccs.t_edw.STATEPROVINCECODE&#0124; &#0124;
    ccs.t_edw.ZIPCODE&#0124; &#0124;
    ccs.edwssnencrypt(ccs.t_edw.SSN)&#0124; &#0124;
    ccs.t_edw.HOMEPHONENUMBER&#0124; &#0124;
    ccs.t_edw.PHOTOCARDINDICATOR&#0124; &#0124;
    ccs.t_edw.ACCOUNTTYPE&#0124; &#0124;
    NVL(ccs.t_edw.InsuranceType , '000' )&#0124; &#0124;
    ccs.t_edw.ASSETPOOLNUMBER&#0124; &#0124;
    ccs.t_edw.STATEMENTHOLDCODE&#0124; &#0124;
    ccs.t_edw.BRANCHNUMBER&#0124; &#0124;
    ccs.t_edw.BANKRUPTCYPREDICTORSCORE&#0124; &#0124;
    ccs.t_edw.DATELASTBANKRUPTCYRESCORE&#0124; &#0124;
    NVL(ccs.t_edw.DATEOPEN,'0000000')&#0124; &#0124;
    ccs.t_edw.DATEEXPIRATION&#0124; &#0124;
    ccs.t_edw.DATECUSTOMERBIRTH&#0124; &#0124;
    ccs.t_edw.DATECLOSEDVOLUNTARY&#0124; &#0124;
    ccs.t_edw.DATECLOSEDINVOLUNTARY&#0124; &#0124;
    ccs.t_edw.DATELASTACTIVE&#0124; &#0124;
    ccs.t_edw.DATELASTPAYMENT&#0124; &#0124;
    ccs.t_edw.DATELASTPURCHASE&#0124; &#0124;
    ccs.t_edw.DATECHARGEOFF&#0124; &#0124;
    NVL(ccs.t_edw.DateLastStatement , '0000000' )&#0124; &#0124;
    ccs.t_edw.DATEHIGHESTBALANCELTD&#0124; &#0124;
    ccs.t_edw.DATELASTCREDITLIMITCHANGE&#0124; &#0124;
    ccs.t_edw.STATUSCLOSED&#0124; &#0124;
    ccs.t_edw.STATUSCREDITREVOKED&#0124; &#0124;
    ccs.t_edw.STATUSPASTDUE&#0124; &#0124;
    ccs.t_edw.STATUSCHARGEOFF&#0124; &#0124;
    NVL(ccs.t_edw.StatusSkipPayment , ' ' )&#0124; &#0124;
    ccs.t_edw.CHARGEOFFTYPE&#0124; &#0124;
    NVL(ccs.t_edw.MinimunPaymentDue , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.CURRENTBALANCE&#0124; &#0124;
    NVL(ccs.t_edw.PreviousStatementBalance , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.BALANCECHARGEDOFF&#0124; &#0124;
    ccs.t_edw.CURRENTCREDITLIMIT&#0124; &#0124;
    ccs.t_edw.ORIGINALCREDITLIMIT&#0124; &#0124;
    NVL(ccs.t_edw.BalancePastDueCycle , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.HIGHESTBALANCELTD&#0124; &#0124;
    NVL(ccs.t_edw.AnnualFeeCharge , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.AVAILABLEMONEY&#0124; &#0124;
    ccs.t_edw.NUMCREDITLIMITINCREASES&#0124; &#0124;
    ccs.t_edw.NUMCREDITLIMITDECREASES&#0124; &#0124;
    NVL(ccs.t_edw.APRPurchases , '000000' )&#0124; &#0124;
    NVL(ccs.t_edw.APRCash , '000000' )&#0124; &#0124;
    NVL(ccs.t_edw.APROldPurchases , '000000' )&#0124; &#0124;
    ccs.t_edw.APRBALTRANSFER1&#0124; &#0124;
    NVL(ccs.t_edw.APRPromoCash , '000000' )&#0124; &#0124;
    NVL(ccs.t_edw.APRPromoPurchases , '000000' )&#0124; &#0124;
    ccs.t_edw.APRBALTRANSFER2&#0124; &#0124;
    NVL(ccs.t_edw.RateTypePurchases , ' ' )&#0124; &#0124;
    NVL(ccs.t_edw.RateTypeCash , ' ' )&#0124; &#0124;
    ccs.t_edw.RATETYPEOLDPURCHASES&#0124; &#0124;
    ccs.t_edw.RATETYPEBALTRANSFER1&#0124; &#0124;
    ccs.t_edw.RATETYPEPROMOCASH&#0124; &#0124;
    ccs.t_edw.RATETYPEPROMOPURCHASES&#0124; &#0124;
    ccs.t_edw.RATETYPEBALTRANSFER2&#0124; &#0124;
    NVL(ccs.t_edw.ADBPurchases , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.ADBCash , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.ADBOLDPURCHASES&#0124; &#0124;
    ccs.t_edw.ADBBALTRANSFER1&#0124; &#0124;
    ccs.t_edw.ADBPROMOCASH&#0124; &#0124;
    ccs.t_edw.ADBPROMOPURCHASES&#0124; &#0124;
    ccs.t_edw.ADBBALTRANSFER2&#0124; &#0124;
    ccs.t_edw.ASSESSEDFEEANNUAL&#0124; &#0124;
    NVL(ccs.t_edw.AssessedFeeCash , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AssessedFeeFinanceCharges, '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AssessedFeeInsurance , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AssessedFeeLate , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AssessedFeeOverlimit , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.ASSESSEDFEERETURNEDCHECK&#0124; &#0124;
    NVL(ccs.t_edw.BilledTotalDollars , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.BilledPurchases , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.BilledCash , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.BILLEDOLDPURCHASES&#0124; &#0124;
    ccs.t_edw.BILLEDBALTRANSFER1&#0124; &#0124;
    ccs.t_edw.BILLEDPROMOCASH&#0124; &#0124;
    ccs.t_edw.BILLEDPROMOPURCHASES&#0124; &#0124;
    ccs.t_edw.BILLEDBALTRANSFER2&#0124; &#0124;
    ccs.t_edw.BILLEDMISC&#0124; &#0124;
    NVL(ccs.t_edw.BilledFinanceCharges , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesPurchases , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesCashAdvances , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.NEWCHARGESCONVCHECK&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesATM , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.NEWCHARGESBALXFERPURCH&#0124; &#0124;
    ccs.t_edw.NEWCHARGESBALXFERCHECK&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesFinanceCharges , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesCashFees , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesInsuranceFees , '000000000000000' )&#0124; &#0124;
    ccs.t_edw.NEWCHARGESRETURNEDCHECKS&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesOverlimitFees , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesPurchaseFC , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesCashFC , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesAnnualFees , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NewChargesLateFees , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AmountOfPayments , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.AmountOfCredits , '000000000000000' )&#0124; &#0124;
    NVL(ccs.t_edw.NumberOfPurchases , '00000' )&#0124; &#0124;
    NVL(ccs.t_edw.NumberOfCashAdvances , '00000' )&#0124; &#0124;
    ccs.t_edw.TS1COMPANYNUMBER&#0124; &#0124;
    ccs.t_edw.COUNTRYCODE&#0124; &#0124;
    ' '&#0124; &#0124; -- MCIF Close code
    ccs.t_edw.FILENUMBER&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    '00000'&#0124; &#0124;
    ' '&#0124; &#0124;
    '000000000000000'&#0124; &#0124;
    '0000000'&#0124; &#0124;
    '00000'&#0124; &#0124;
    ' '&#0124; &#0124;
    '000000000000000'&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    ' '&#0124; &#0124;
    DECODE(ccs.t_account.prodind, 1, ' ', 'F')
    FROM
    ccs.t_edw,
    ccs.t_account
    WHERE ccs.t_edw.accountid = ccs.t_account.accountid
    AND ccs.t_account.dateopen = to_date(ccs.t_edw.DATEOPEN,'yyyyddd')
    AND ccs.t_account.dateopen < (add_months(dtDateProcess,1)-1);
    BEGIN
    SELECT max(processdate)
    INTO dtDateProcess
    FROM ccs.t_processlog
    WHERE filename = 'ACCTINFO';
    -- Create a log entry in the t_processlog
    INSERT INTO ccs.t_processlog
    (filename,processdate,completioncode)
    VALUES
    ('EDWEXTRACT',dtDateProcess,9);
    SELECT max(processid)
    INTO dPid
    FROM ccs.t_processlog
    WHERE filename = 'EDWEXTRACT'
    AND processdate = dtDateProcess;
    iRetValue := CCS.StartPID(dPid, 0, 0);
    ccs.populateedw92(1, dtDateProcess);
    IF (SQLCODE != 0) THEN
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 99, 'ccs.populateedw92 failed! See t_exception for error.',0);
    RAISE EDW92;
    END IF;
    ccs.populateedw54(2, dtDateProcess);
    IF (SQLCODE != 0) THEN
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 99, 'ccs.populateedw54 failed! See t_exception for error.',0);
    RAISE EDW54;
    END IF;
    OPEN edw_extract_cur;
    -- Caution: UTL_FILE.FOPEN using w option! Will overwrite existing file!
    outfile_handle := UTL_FILE.FOPEN(outfile_dir,outfile_name,'w',1437);
    IF (SQLCODE != 0) THEN
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 99, 'Problem creating data file! See t_exception for error.',0);
    RAISE FILE_OPEN_ERROR;
    END IF;
    LOOP
    FETCH edw_extract_cur INTO szdata_rec;
    EXIT WHEN edw_extract_cur%NOTFOUND;
    UTL_FILE.PUT_LINE(outfile_handle,szdata_rec);
    IF (SQLCODE != 0) THEN
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 99, 'Problem creating data file! See t_exception for error.',0);
    RAISE PUTLINE_ERROR;
    END IF;
    END LOOP;
    -- update t_processlog with status of 1 for dPid
    UTL_FILE.FCLOSE (outfile_handle);
    IF (SQLCODE != 0) THEN
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 99, 'Problem closing data file! See t_exception for error.',0);
    RAISE FILE_CLOSE_ERROR;
    END IF;
    -- Drop index on t_edw table
    icursor_name := sys.dbms_sql.open_cursor;
    sys.dbms_sql.parse(icursor_name,'DROP INDEX ccs.i_t_edw_accountid ', sys.dbms_sql.v7);
    irows_processed := sys.dbms_sql.execute(icursor_name);
    sys.dbms_sql.close_cursor(icursor_name);
    IF (sqlcode != 0) THEN
    RAISE DROP_INDEX_FLAG;
    ELSE
    COMMIT;
    END IF;
    -- Recreate index on t_edw table
    icursor_name := sys.dbms_sql.open_cursor;
    sys.dbms_sql.parse(icursor_name,'CREATE INDEX ccs.i_t_edw_accountid ON ccs.t_edw (accountid) tablespace tsindex storage (initial 30m next 30m pctincrease 0) parallel(degree 5) nologging', sys.dbms_sql.v7);
    irows_processed := sys.dbms_sql.execute(icursor_name);
    sys.dbms_sql.close_cursor(icursor_name);
    IF (sqlcode != 0) THEN
    RAISE CREATE_INDEX_FLAG;
    ELSE
    iRetValue := CCS.UpdatePIDDesc(dPid, 1, 1, 'EDWEXTRACT Completed successfully.',0);
    COMMIT;
    END IF;
    EXCEPTION WHEN EDW54 THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'The populateedw54 failed! Contact support personnel.');
    WHEN EDW92 THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'The populateedw92 failed! Contact support personnel.');
    WHEN DROP_INDEX_FLAG THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Failed to drop index on t_edw table! Contact support personnel.');
    WHEN CREATE_INDEX_FLAG THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Failed to create index on t_edw table! Contact support personnel.');
    WHEN NO_DATA_FOUND THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'No data found! Contact support personnel.');
    WHEN FILE_CLOSE_ERROR THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Unable to close data file! Contact support personnel.');
    WHEN PUTLINE_ERROR THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLE   rrText,'Failed to write szdata_rec to file! Contact support personnel.');
    WHEN FILE_OPEN_ERROR THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Failed to open data file! Contact support personnel.');
    WHEN UTL_FILE.INVALID_PATH THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Invalid path! Contact support personnel.');
    WHEN UTL_FILE.INVALID_MODE THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Invalid mode! Contact support personnel.');
    WHEN UTL_FILE.INVALID_FILEHANDLE THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Bad file handle! Contact support personnel.');
    WHEN UTL_FILE.INVALID_OPERATION THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Invalid operation! Contact support personnel.');
    WHEN UTL_FILE.WRITE_ERROR THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Unable to write to file, ERROR! Contact support personnel.');
    WHEN UTL_FILE.INTERNAL_ERROR THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'Utl_file internal error! Contact support personnel.');
    WHEN OTHERS THEN
    szSQLErrText := SUBSTR(SQLERRM,1,250);
    iRetValue := ccs.ExceptionWrite(dPid,szSQLErrText,'EDWEXTRACT failed due to unknown reason! Contact support personnel.');
    END;
    /I guess my confusion is how can I put a trigger on the t_processlog table to start a job when another finishes, and still have the job called make an entry into the t_processlog? I looked at the code for suggested work around, but I'm a little confused as to what is going on. Can anyone give me an idea for what to do in the situation? Thanks.
    Adam Bolduc
    null

    I didn't see your coding but i think you are selecting the same table through the procedure, on which you have written the db trigger.
    In that case it will alway gives you mutating error.
    Sanjeev

  • How to get around ora-ORA-04091: table SSBOSS.SSTRMAST is mutating, trigger

    hi,
    Does anyone know how one would get around this problem please ?
    Here is my dbase trig:
    CREATE OR REPLACE TRIGGER SSBOSS.new_not_greater_than_net
    BEFORE INSERT OR UPDATE OF newrent ON SSBOSS.SSTRMAST
    REFERENCING NEW AS new OLD AS old
    FOR each row
    DECLARE
    not_permitted EXCEPTION;
    vnum number := ssboss.nik_f;
    BEGIN
    IF :new.NEWRENT > vnum then
    --AND :old.DELETED = 'N' THEN
    RAISE not_permitted;
    END IF;
    EXCEPTION
    WHEN not_permitted THEN
    RAISE_APPLICATION_ERROR
    (-20001, 'NEWRENT:'||:new.newrent||' '||'OLDRENT:'||' '||:old.netrent||'Action not permitted. Contribution (sstrmast.newrent) value '
    ||:new.NEWRENT
    ||' exceeds GROSS rental value (sstrmast.netrent) ');
    END;
    Here is my problem:
    SQL> update sstrmast set newrent = 11;
    update sstrmast set newrent = 11
    ERROR at line 1:
    ORA-04091: table SSBOSS.SSTRMAST is mutating, trigger/function may not see it
    ORA-06512: at "SSBOSS.NIK_F", line 4
    ORA-06512: at "SSBOSS.NEW_NOT_GREATER_THAN_NET", line 4
    ORA-04088: error during execution of trigger 'SSBOSS.NEW_NOT_GREATER_THAN_NET'
    I understand why but not how to correct?
    Thanks,
    nikolia.

    Hello,
    This problem as you might be knowing occurs when you try to select the data from the same table on which the trigger is written. Also this problem is only with the row level trigger and not with the statement level trigger. However the limitation of the statement level trigger is it can not refer to :NEW or :OLD. So now the solution is to capture the value of :NEW or :OLD in the row level trigger (no select statement here) and store it in some global variable. And how do you get the global variable? Using package specification ! a variable declared in a package specification is global in nature. Then use the value so stored in the statement level trigger in the select statement. It will work. Other solution is to use pragma autonomous transaction. Try and let us know. All the best.
    Regards

  • ORA-04091: table QA.LIB_ACCESSION_LOG is mutating

    hi
    while executing this:
    SQL> insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11;
    insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11
    ERROR at line 1:
    ORA-04091: table QA.LIB_ACCESSION_LOG is mutating, trigger/function may not
    see it
    ORA-06512: at "QA.TRG_ACCESSION_LOG", line 2
    ORA-04088: error during execution of trigger 'QA.TRG_ACCESSION_LOG'
    how can i do this insert and resolve this error. should i switch off the constraints? and what will happen when i switch on the constraints?

    ORA-04091, ORA-06512, ORA-04088.

  • Getting ORA-04091: table SALUSER.PRM_M_EMPLOYEE is mutating, trigger/

    create or replace trigger prm_tr_emp_active
    before  update or insert on  prm_m_employee
    referencing NEW as new_data  OLD as old_data
    for each row
    declare
        v_tag       number ;
         --PRAGMA AUTONOMOUS_TRANSACTION;
    begin
        select NVL2( PMEP_FATHER_NAME, 1, 0) * NVL2( PMEP_MOTHER_NAME, 1, 0) *
               NVL2( PMEP_NATIONALITY, 1, 0) * NVL2( PMEP_RELIGION_CODE, 1, 0)*
               NVL2( PMEP_SEX, 1, 0) * NVL2( PMEP_DOB, 1, 0) * NVL2( PMEP_QUALIFICATION, 1, 0) *
               NVL2( PMEP_APPOINTMENT_TYPE, 1, 0) * NVL2( PMEP_DESIGNATION, 1, 0) *
               NVL2( PMEP_DOJ, 1, 0) * NVL2( PMEP_LOCATION_CODE, 1, 0) * NVL2( PMEP_SKILL_CODE, 1, 0) *
               NVL2( PMEP_GRADE_CODE, 1, 0) * NVL2( PMEP_ONSITE_TAG, 1, 0) * NVL2( PMEP_NIL_SALARY_TAG, 1, 0) *
               NVL2( PMEP_HOLD_EBC_TAG, 1, 0) * NVL2( PMEP_EX_SERVICE_MAN, 1, 0) *
               NVL2( PMEP_NRI_STATUS, 1, 0) * NVL2( PMEP_PAYMENT_CURRENCY, 1, 0) *
               NVL2( PMEP_TAX_BY_COMPANY, 1, 0) * NVL2( PMEP_FNF_SETTLED, 1, 0) *
               NVL2( PMEP_PAN_NO, 1, 0)  * NVL2( PMEP_STATE_CODE, 1, 0) * NVL2( PMEP_MARITAL_STATUS, 1, 0)*
               NVL2( PMEP_SAF_MEMBER, 1, 0) * NVL2( PMEP_SAF_THRU_SALARY, 1, 0) *
               NVL2( PMEP_SAF_ENCASHMENT, 1, 0) * NVL2( PMEP_TDS_ON_PF_INT, 1, 0) *
               NVL2( PMEP_PROCESS_BY_SSC, 1, 0) * NVL2( PMEP_CITY_CODE, 1, 0)
        into v_tag
        from prm_m_employee
        where pmep_emp_id = :new_data.pmep_emp_id ;
           if v_tag = 1 then
                update prm_m_employee set
                 pmep_active = 'Y'
                where pmep_emp_id =  :new_data.pmep_emp_id ;
           else
                update prm_m_employee set
                 pmep_active = 'N'
                where pmep_emp_id =  :new_data.pmep_emp_id ;      
           end if ;
        --COMMIT;    
    end ;

    Assuming that pmep_emp_id is the primary key of the table, it doesn't appear that you need to do a SELECT against the table or an UPDATE against the table. If that is the primary key, then you should just need to manipulate the :new.column_name values for the row you are modifying, i.e.
    v_tag := NVL2( :new.pmep_father_name, 1, 0 ) * NVL2( :new.pmep_mother_name, 1, 0 ) *
             NVL2( :new.pmep_nationality, 1, 0 ) * ...
    IF( v_tag = 1 )
    THEN
      :new.pmep_active := 'Y';
    ELSE
      :new.pmep_active := 'N';
    END IF;You would absolutely want to avoid trying to use an autonomous transaction here. The autonomous transaction would not be able to see data inserted by the current transaction and commits happen outside the scope of the calling transaction. Barring a logging operation where you want the log to remain even if the logging event is rolled back (i.e. log attempts to delete a row even if the attempt fails), you should not use autonomous transactions in triggers. And you should not be using autonomous transactions to work around mutating trigger errors.
    Justin
    Edited by: Justin Cave on Mar 11, 2009 2:23 AM

  • Storage for Foreign Keys and Function based indexes

    This may well be the silliest question of the day, but is it possible to specify the storage for a Foreign key or a function based index? I'm not even sure that it would make sense.

    Well, a foreign key constraint is not a segment, nor is any other type of constraint. However, a function-based index is a segment, just like any other index. So, in that case, specify a tablespace, just like you would with any other index.
    Something like this:
    create index my_fbi on my_tab(upper(last_name)) tablespace my_index_tablespace;
    -Mark
    Message was edited by:
    mbobak
    Fixed minor typo.

  • Intermedia and function-based indexes

    Is it valid to use function-based indexing to create an intermedia index type ?

    I am interested in this, what's your motivation for function-based index in interMedia text? What kind of function are you going to design?
    Honglin

  • SQL, PL/SQL functions, and ORA-04091 table is mutating

    Dears,
    Recently a question came up in an Oracle French forum about an insert/select that is throwing ORA-04091: table xxxx is mutating, trigger/function may not see it error in 11g while the same insert/select was working very well in 10g. The original poster gave a scenario that is easily reproducible. I am wondering what database release is correct the one throwing the error(11g) or the other one accepting the insert/select(10g)?
    *10g*
    mhouri.world > select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi               
    PL/SQL Release 10.2.0.4.0 - Production                                         
    CORE     10.2.0.4.0     Production                                                     
    TNS for Solaris: Version 10.2.0.4.0 - Production                               
    NLSRTL Version 10.2.0.4.0 - Production                                         
    mhouri.world > create table t_read_consistency (id number, vc varchar2(15), primary key (id));
    Table created.
    mhouri.world > insert into
      2        t_read_consistency
      3      select
      4        rownum id,
      5        rpad('a',15,'a')
      6      from
      7        dual
      8      connect by
      9        level<=1000;
    1000 rows created.
    mhouri.world > commit;
    Commit complete.
    mhouri.world > create or replace function f_read_consistency return varchar2
      2       as
      3        lv_vc  t_read_consistency.vc%type;
      4       begin
      5         select trc.vc
      6         into lv_vc
      7          from t_read_consistency trc
      8         where trc.id = 70 ;
      9        return lv_vc;
    10     end f_read_consistency;
    11    /
    Function created.
    mhouri.world >insert into
      2        t_read_consistency (id, vc)
      3      select
      4         1001
      5        ,f_read_consistency
      6      from dual;
          ,f_read_consistency
    ERROR at line 5:
    ORA-04091: table MHOURI.T_READ_CONSISTENCY is mutating, trigger/function may not see it
    ORA-06512: at "MHOURI.F_READ_CONSISTENCY", line 5
    _11g_
    mohamed@mhouri> select * from v$version;
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production         
    PL/SQL Release 11.2.0.1.0 - Production                                         
    CORE     11.2.0.1.0     Production                                                     
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production                        
    NLSRTL Version 11.2.0.1.0 - Production                                         
    mohamed@mhouri> create table t_read_consistency (id number, vc varchar2(15), primary key (id));
    Table created.
    mohamed@mhouri> insert into
      2    t_read_consistency
      3  select
      4    rownum id,
      5    rpad('a',15,'a')
      6  from
      7    dual
      8  connect by
      9    level<=1000;
    1000 rows created.
    mohamed@mhouri>  create or replace function f_read_consistency return varchar2
      2   as
      3    lv_vc  t_read_consistency.vc%type;
      4   begin
      5     select trc.vc
      6     into lv_vc
      7      from t_read_consistency trc
      8     where trc.id = 70 ;
      9    return lv_vc;
    10  end f_read_consistency;
    11  /
    Function created.
    mohamed@mhouri> insert into
      2    t_read_consistency (id, vc)
      3  select
      4     1001
      5    ,f_read_consistency
      6  from dual;
      ,f_read_consistency
    ERROR at line 5:
    ORA-04091: table MOHAMED.T_READ_CONSISTENCY is mutating, trigger/function may
    not see it
    ORA-06512: at "MOHAMED.F_READ_CONSISTENCY", line 5 So far so good. Same behaviour for both releases. But let's bring a small change to the PL/SQL function to be as close as the example given in the French Forum
    _10g where the select/insert was working without error_:
    mhouri.world > select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi               
    PL/SQL Release 10.2.0.4.0 - Production                                         
    CORE     10.2.0.4.0     Production                                                     
    TNS for Solaris: Version 10.2.0.4.0 - Production                               
    NLSRTL Version 10.2.0.4.0 - Production       
    mhouri.world > create type t_read_cs as object (id number,vc varchar2(15));
      2  /
    Type created.
    mhouri.world > create type t_read_cs_tab  as table of t_read_cs;
      2  /
    Type created.
    mhouri.world > create or replace function f_read_consistency_tab
      2  return t_read_cs_tab
      3    as
      4      lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
      5      j  binary_integer := 0;
      6    begin
      7        for x in (select
      8                      id,
      9                      vc
    10                   from  t_read_consistency trs
    11                  where trs.id <= 10
    12       ) loop
    13 
    14          j := j +1;
    15          lc_t_read_cs_tab.extend;
    16          lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
    17     end loop;
    18     RETURN lc_t_read_cs_tab;
    19   end f_read_consistency_tab;
    20  /
    Function created.
    mhouri.world > select count(1) from t_read_consistency;
      COUNT(1)                                                                                                             
          1000                                                                                                             
    mhouri.world > select count(1)
      2  from (select * from table(f_read_consistency_tab));
      COUNT(1)                                                                                                             
            10                                                                                                             
    mhouri.world > insert into t_read_consistency
      2         (id,vc)
      3      select id,vc
      4   from table(f_read_consistency_tab)
      5  ;
    10 rows created.
    mhouri.world > select count(1) from t_read_consistency;
      COUNT(1)                                                                                                             
          1010            
    _11g where the same insert/select is throwing an error:_
    mohamed@mhouri> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    mohamed@mhouri> create type t_read_cs as object (id number,vc varchar2(15));
      2  /
    Type created.
    mohamed@mhouri> create type t_read_cs_tab  as table of t_read_cs;
      2  /
    Type created.
    mohamed@mhouri> create or replace function f_read_consistency_tab
      2      return t_read_cs_tab
      3        as
      4          lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
      5          j  binary_integer := 0;
      6        begin
      7            for x in (select
      8                          id,
      9                          vc
    10                      from  t_read_consistency trs
    11                     where trs.id <= 10
    12          ) loop
    13 
    14            j := j +1;
    15             lc_t_read_cs_tab.extend;
    16             lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
    17        end loop;
    18        RETURN lc_t_read_cs_tab;
    19      end f_read_consistency_tab;
    20    /
    Function created.
    mohamed@mhouri> select count(1) from t_read_consistency;
      COUNT(1)                                                                     
          1000                                                                     
    mohamed@mhouri> select count(1) from (select * from table(f_read_consistency_tab));
      COUNT(1)                                                                     
            10                                                                     
    mohamed@mhouri> insert into t_read_consistency
      2            (id,vc)
      3          select id,vc
      4      from table(f_read_consistency_tab)
      5     ;
        from table(f_read_consistency_tab)
    ERROR at line 4:
    ORA-04091: table MOHAMED.T_READ_CONSISTENCY is mutating, trigger/function may
    not see it
    ORA-06512: at "MOHAMED.F_READ_CONSISTENCY_TAB", line 7 In addition, one of the posters spotted out very judiciously that if we slightly change the definition of the table t_read_consistency in 11g, strangely the insert/select will work correctly in this data base as shown below:
    ohamed@mhouri> drop table tr_read_consistency;
    Table dropped.
    mohamed@mhouri> create table tr_read_consistency
      2      as select rownum rn,
      3                trs.*
      4      from
      5         t_read_consistency trs;
    Table created.
    mohamed@mhouri> insert into tr_read_consistency
      2                 (rn, id,vc)
      3              select rownum, id,vc
      4           from table(f_read_consistency_tab);
    10 rows created.So is this a regression? or a corrected bug during upgrade?
    Thanks in advance
    Mohamed Houri

    I just followed the doc links provided by Tubby, which have 100% Correct answer. See below :
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> show user;
    USER is "SCOTT"
    SQL> create type t_read_cs as object (id number,vc varchar2(15));
      2  /
    Type created.
    SQL> create type t_read_cs_tab  as table of t_read_cs;
      2  /
    Type created.
    SQL> create table t_read_consistency (id number, vc varchar2(15), primary key (id));
    Table created.
    SQL> create or replace function f_read_consistency_tab
      2  return t_read_cs_tab
      3  as
      4  lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
      5  j  binary_integer := 0;
      6  begin
      7  for x in (select
      8  id,
      9  vc
    10  from  t_read_consistency trs
    11  where trs.id <= 10
    12  ) loop
    13  j := j +1;
    14  lc_t_read_cs_tab.extend;
    15  lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
    16  end loop;
    17  RETURN lc_t_read_cs_tab;
    18  end f_read_consistency_tab;
    19  /
    Function created.
    SQL> insert into
      2  t_read_consistency
      3  select
      4  rownum id,
      5  rpad('a',15,'a')
      6  from
      7  dual
      8  connect by
      9  level<=1000;
    1000 rows created.
    SQL> select count(1) from t_read_consistency;
      COUNT(1)
          1000
    SQL> select count(1) from (select * from table(f_read_consistency_tab));
      COUNT(1)
            10
    SQL> insert into t_read_consistency
      2  (id,vc)
      3  select id,vc
      4  from table(f_read_consistency_tab);
    from table(f_read_consistency_tab)
    ERROR at line 4:
    ORA-04091: table SCOTT.T_READ_CONSISTENCY is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.F_READ_CONSISTENCY_TAB", line 7
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace function f_read_consistency_tab
      2  return t_read_cs_tab
      3  as
      4  lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
      5  j  binary_integer := 0;
      6  PRAGMA AUTONOMOUS_TRANSACTION; <--- This works as documented in 11.2.0.1
      7  begin
      8  for x in (select
      9  id,
    10  vc
    11  from  t_read_consistency trs
    12  where trs.id <= 10
    13  ) loop
    14  j := j +1;
    15  lc_t_read_cs_tab.extend;
    16  lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
    17  end loop;
    18  RETURN lc_t_read_cs_tab;
    19* end f_read_consistency_tab;
    SQL> /
    Function created.
    SQL> insert into t_read_consistency
      2  (id,vc)
      3  select id,vc
      4  from table(f_read_consistency_tab);
    insert into t_read_consistency
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.SYS_C0011307) violated
    SQL> drop table t_read_consistency purge;
    Table dropped.
    SQL> create table t_read_consistency (id number, vc varchar2(15));
    Table created.
    SQL> insert into
      2  t_read_consistency
      3  select
      4  rownum id,
      5  rpad('a',15,'a')
      6  from
      7  dual
      8  connect by
      9  level<=1000;
    1000 rows created.
    SQL> commit;
    Commit complete.
    SQL> insert into t_read_consistency
      2  (id,vc)
      3  select id,vc
      4  from table(f_read_consistency_tab);
    10 rows created.
    SQL> commit;
    Commit complete.
    SQL>So, you have to add only PRAGMA AUTONOMOUS_TRANSACTION; before begin in your function code to avoid ORA-04091 in 11.2.0.1
    But, All thanks to Tubby who pointed us to the correct documentation link.
    Regards
    Girish Sharma

  • ORA-04091 - Table  mutating

    Hi,
    I have a trigger which executes a stored procedure.
    Trigger
    =======
    CREATE OR REPLACE TRIGGER mhubadmin.call_proc_ratesheet_new
    after INSERT OR delete ON mhubadmin.pvt_br_ratesheet
    FOR EACH ROW
    declare
    var_orgid number;
    begin
    if inserting then
    select org_child_id into var_orgid from business_relationship where br_id=:new.br_id;
    mhubadmin.proc_ratesheet_new(var_orgid);
    else
    select org_child_id into var_orgid from business_relationship where br_id=:old.br_id;
    mhubadmin.proc_ratesheet_new(var_orgid);
    end if;
    end;
    Stored Procedure
    ==============
    CREATE OR REPLACE PROCEDURE proc_ratesheet_new(var_orgid in number)
    IS
    cursor c3 is select distinct(purs.user_id) from hubuser hu
    inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
                   where hu.ORG_ID=var_orgid;
    cursor c1(varUser_id number) is select purs.user_id,purs.ratesheet_id from hubuser hu
    inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
                   where hu.ORG_ID=var_orgid and purs.USER_ID=varUser_id;
    cursor c2(varUser_id number) is select hu.user_id,pbr.ratesheet_id from HUBUSER hu
                             inner join BUSINESS_RELATIONSHIP br on hu.ORG_ID=br.ORG_CHILD_ID
                             inner join PVT_BR_RATESHEET pbr on br.BR_ID=pbr.BR_ID
                                  where hu.user_id in(select distinct(purs.USER_ID) from hubuser hu
                                       inner join PVT_USER_RATESHEET purs
                                                                     on hu.USER_ID=purs.USER_ID
                                                 where hu.ORG_ID=var_orgid) and hu.user_id=varUser_id;
    foundFlag boolean;
    BEGIN
         for c3var in c3 loop
    for c2var in c2(c3var.user_id) loop
              foundFlag:=false;
              for c1var in c1(c3var.user_id) loop
                   if c2var.ratesheet_id=c1var.ratesheet_id then
                        foundFlag:=true;
                             exit;
                        end if;
                   end loop;
                   if foundFlag=False then
                   insert into pvt_user_ratesheet (username_ratesheet_id,user_id,ratesheet_id) values (SEQ_USER_RATESHEET.nextval,c3var.user_id,c2var.ratesheet_id);
                   end if;
              end loop;
    end loop;
         for c3var in c3 loop
              for c1var in c1(c3var.user_id) loop
              foundFlag:=false;
              for c2var in c2(c3var.user_id) loop
                        if c1var.ratesheet_id=c2var.ratesheet_id then
                        foundFlag:=true;
                        exit;
                        end if;
                   end loop;
                   if foundFlag=False then
                   delete from pvt_user_ratesheet where user_id=c3var.user_id and ratesheet_id=c1var.ratesheet_id;
                   end if;
              end loop;
    end loop;
    --EXCEPTION
    --- WHEN OTHERS THEN
    --- DBMS_OUTPUT.put_line (SQLCODE||' '|| SQLERRM);
    END;
    But while firing this trigger I am getting an error like this,
    ORA-04091: table MHUBADMIN.PVT_BR_RATESHEET is mutating, trigger/function may not see it
    ORA-06512: at "MHUBADMIN.PROC_RATESHEET_NEW", line 14
    ORA-06512: at "MHUBADMIN.PROC_RATESHEET_NEW", line 25
    ORA-06512: at "MHUBADMIN.CALL_PROC_RATESHEET_NEW", line 6
    ORA-04088: error during execution of trigger 'MHUBADMIN.CALL_PROC_RATESHEET_NEW'
    Regards,
    Mathew

    Yes, and I'm reading this on a computer screen!
    What functional requirement are you trying to achieve?
    And have you googled? If so, you would have found this
    http://asktom.oracle.com/tkyte/Mutate/index.html
    Cheers,
    Colin

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

    ORA-04091: table blah is mutating, trigger/function may not see it
    ORA-06512: at "AOLALERE.CHK_FOR_POST", line 7
    ORA-06512: at "AOLALERE.CHK_FOR_POST", line 20
    ORA-06512: at "AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE", line 14
    ORA-04088: error during execution of trigger 'AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE'
    TRIGGER preproddta_f41021_after_update
    after insert or update
    on preproddta.f41021
    for each row
    declare
    --nothing to declare
         --pragma autonomous_transaction;
         l_lipqoh preproddta.f41021.lipqoh%type;
         l_lipcom preproddta.f41021.lipcom%type;
         l_lihcom preproddta.f41021.lihcom%type;
         l_lilots preproddta.f41021.lilots%type;
         l_lilocn preproddta.f41021.lilots%type;
         l_lilotn preproddta.f41021.lilots%type;
    l_quantity_avail f41021_audit.quantity_avail%type;
         l_rec_chk f41021_audit.liitm%type;
    begin
    --chk_for_post(:new.limcu,:new.liitm);
    --if :old.limcu <> '      GBD001' then return; end if;
    if :old.lipqoh = :new.lipqoh then
    l_lipqoh := :old.lipqoh;
    else
    l_lipqoh := :new.lipqoh;
    end if;
    if :old.lipcom = :new.lipcom then
    l_lipcom := :old.lipcom;
    else
    l_lipcom := :new.lipcom;
    end if;
    if :old.lihcom = :new.lihcom then
    l_lihcom := :old.lihcom;
    else
    l_lihcom := :new.lihcom;
    end if;
    if :old.lilots = :new.lilots then
    l_lilots := :old.lilots;
    else
    l_lilots := :new.lilots;
    end if;
    if l_lilots <> ' ' then
    l_quantity_avail := - (l_lipcom - l_lihcom);
    else
    l_quantity_avail := l_lipqoh - (l_lipcom + l_lihcom);
    end if;
    l_rec_chk := rec_chk(:old.limcu,:old.liitm,l_lilots);
    if l_rec_chk is not null then
         begin
    update f41021_audit
         set lipqoh = l_lipqoh,
         lipcom = l_lipcom,
    lihcom = l_lihcom,
              quantity_avail = l_quantity_avail
         where limcu = :old.limcu
         and liitm = :old.liitm
         and lilotn = :old.lilotn
         and lilocn = :old.lilocn
         and lilots = l_lilots;
         end;
    else
    -- insert record into audit table
    begin
    insert into f41021_audit
    (limcu,
                        liitm,
                                  lipqoh,
                                  lipcom,
                                  lihcom,
                                  lilots,
                                       lilotn,
                                       lilocn,
                                       quantity_avail)
    values
    (:old.limcu,
    :old.liitm,
    l_lipqoh,
                                  l_lipcom,
                                  l_lihcom,
                                  l_lilots,
                                       :old.lilotn,
                                       :old.lilocn,
                                       l_quantity_avail);
         end;
    end if;
    end;
    create or replace procedure chk_for_post(p_limcu in varchar2,
    p_liitm in number)
    is
    cursor get_bra_qa(p_limcu in varchar2,
    p_liitm in number)is
    select liitm,
         (sum(lipqoh) - sum(lipcom + lihcom)) qual_avail
    from preproddta.f41021 a, preproddta.f4101 b
    where limcu = p_limcu
    and liitm = imitm
    and liitm = p_liitm
    group by liitm,imdsc1;
    l_bra_qa get_bra_qa%rowtype;
    l_itm_bran_qa t_f41021_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
    begin
    open get_bra_qa(p_limcu,p_liitm);
    fetch get_bra_qa into l_bra_qa;
    close get_bra_qa;
    if l_itm_bran_qa.quantity_avail is null then ---This indicate that there is no record for
    ---quantity available for the item based on the branch .
    l_itm_bran_qa := new t_f41021_itm_bran_qa(p_liitm);
         begin
         l_itm_bran_qa.liitm := p_liitm;
         l_itm_bran_qa.limcu := p_limcu;
         l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
         l_itm_bran_qa.add_it;
         commit;
         end;     
    else
    l_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
         if l_itm_bran_qa.quantity_avail = l_bra_qa.qual_avail then
         null; return;
         else
         begin
         l_itm_bran_qa.liitm := p_liitm;
         l_itm_bran_qa.limcu := p_limcu;
         l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
         l_itm_bran_qa.send_to_DB;
         commit;
         end;
         end if;     
    end if;
    end;

    Thanks,
    I comment it out cos it was causing the problem this is the code:
    The following error has occurred:
    ORA-04091: table PREPRODDTA.F41021 is mutating, trigger/function may not see it
    ORA-06512: at "AOLALERE.CHK_FOR_POST", line 7
    ORA-06512: at "AOLALERE.CHK_FOR_POST", line 20
    ORA-06512: at "AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE", line 98
    ORA-04088: error during execution of trigger 'AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE'
    TRIGGER preproddta_f41021_after_update
    after insert or update
    on preproddta.f41021
    for each row
    declare
    --nothing to declare
         --pragma autonomous_transaction;
         l_lipqoh preproddta.f41021.lipqoh%type;
         l_lipcom preproddta.f41021.lipcom%type;
         l_lihcom preproddta.f41021.lihcom%type;
         l_lilots preproddta.f41021.lilots%type;
         l_lilocn preproddta.f41021.lilots%type;
         l_lilotn preproddta.f41021.lilots%type;
    l_quantity_avail f41021_audit.quantity_avail%type;
         l_rec_chk f41021_audit.liitm%type;
    begin
    --if :old.limcu <> '      GBD001' then return; end if;
    if :old.lipqoh = :new.lipqoh then
    l_lipqoh := :old.lipqoh;
    else
    l_lipqoh := :new.lipqoh;
    end if;
    if :old.lipcom = :new.lipcom then
    l_lipcom := :old.lipcom;
    else
    l_lipcom := :new.lipcom;
    end if;
    if :old.lihcom = :new.lihcom then
    l_lihcom := :old.lihcom;
    else
    l_lihcom := :new.lihcom;
    end if;
    if :old.lilots = :new.lilots then
    l_lilots := :old.lilots;
    else
    l_lilots := :new.lilots;
    end if;
    if l_lilots <> ' ' then
    l_quantity_avail := - (l_lipcom - l_lihcom);
    else
    l_quantity_avail := l_lipqoh - (l_lipcom + l_lihcom);
    end if;
    l_rec_chk := rec_chk(:old.limcu,:old.liitm,l_lilots);
    if l_rec_chk is not null then
         begin
    update f41021_audit
         set lipqoh = l_lipqoh,
         lipcom = l_lipcom,
    lihcom = l_lihcom,
              quantity_avail = l_quantity_avail
         where limcu = :old.limcu
         and liitm = :old.liitm
         and lilotn = :old.lilotn
         and lilocn = :old.lilocn
         and lilots = l_lilots;
         end;
    else
    -- insert record into audit table
    begin
    insert into f41021_audit
    (limcu,
                        liitm,
                                  lipqoh,
                                  lipcom,
                                  lihcom,
                                  lilots,
                                       lilotn,
                                       lilocn,
                                       quantity_avail)
    values
    (:old.limcu,
    :old.liitm,
    l_lipqoh,
                                  l_lipcom,
                                  l_lihcom,
                                  l_lilots,
                                       :old.lilotn,
                                       :old.lilocn,
                                       l_quantity_avail);
         end;
    end if;
    chk_for_post(:new.limcu,:new.liitm);
    return;
    end;
    create or replace procedure chk_for_post(p_limcu in varchar2,
    p_liitm in number)
    is
    cursor get_bra_qa(p_limcu in varchar2,
    p_liitm in number)is
    select liitm,
    (sum(lipqoh) - sum(lipcom + lihcom)) qual_avail
    from preproddta.f41021 a, preproddta.f4101 b
    where limcu = p_limcu
    and liitm = imitm
    and liitm = p_liitm
    group by liitm,imdsc1;
    l_bra_qa get_bra_qa%rowtype;
    l_itm_bran_qa t_f41021_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
    begin
    open get_bra_qa(p_limcu,p_liitm);
    fetch get_bra_qa into l_bra_qa;
    close get_bra_qa;
    if l_itm_bran_qa.quantity_avail is null then ---This indicate that there is no record for
    ---quantity available for the item based on the branch .
    l_itm_bran_qa := new t_f41021_itm_bran_qa(p_liitm);
    begin
    l_itm_bran_qa.liitm := p_liitm;
    l_itm_bran_qa.limcu := p_limcu;
    l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
    l_itm_bran_qa.add_it;
    commit;
    end;
    else
    l_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
    if l_itm_bran_qa.quantity_avail = l_bra_qa.qual_avail then
    null; return;
    else
    begin
    l_itm_bran_qa.liitm := p_liitm;
    l_itm_bran_qa.limcu := p_limcu;
    l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
    l_itm_bran_qa.send_to_DB;
    commit;
    end;
    end if;
    end if;
    end;
    Please sugesst any work around. I need to call calculate changes based on the insert or updates

  • ORA-04091 table string.string is mutating, trigger/function may not see it

    When I am tending to delete something from my table I received this message.
    I defined a PL/SQL function reads data from that table. Is that meaning I could not modify anything in table once I have some PL/SQL defined on that? It sounds ridiculour. Or I missed some points?
    Anyone could help me out?
    Many thanks,
    Qiang

    In get_point_coordinates(point_id, layerid), it does not have any codes deleting thing from point_tab.
    Its functionality is to find out that specified point;
    put its coordinates into SDO_GEOMETRY object and return as function value.
    However, oracle does not allow me to delete any data from point table since then.It is saying that function (get_point_coordinates) can not know mutating tables.
    When I run delete task:
    delete from point$_view where point_id = 1;
    I got errors:
    ERROR at line 1:
    ORA-04091: table POINT$_TABLE is mutating, trigger/functio
    n may not see it
    ORA-06512: at "GET_POINT_COORDINATES", /* THIS LINE REPORS ERROR*/ Look at codes below.
    The following is code of function: GET_POINT_COORDINATES
    FUNCTION GET_POINT_COORDINATES(pPoint_ID IN NUMBER, player_ID IN NUMBER)
    RETURN MDSYS.SDO_GEOMETRY DETERMINISTIC IS
    PSRID NUMBER :=NULL:
    PLON NUMBER := NULL;
    PLAT NUMBER := NULL;
    CURSOR get_lonlat(ppoint_id IN NUMBER, player_id IN NUMBER) IS SELECT LON,LAT
    FROM POINT$_VIEW /* THIS LINE REPORS ERROR*/
    WHERE player_id = layer_id AND ppoint_id = point_id;
    BEGIN
    PSRID := 8265;
    OPEN get_lonlat(pPoint_ID,Player_ID);
    FETCH get_lonlat INTO PLON, PLAT;
    RETURN MDSYS.SDO_GEOMETRY(2001,PSRID,MDSYS.SDO_POINT_TYPE(PLON,PLAT,NULL),NULL ,NULL);
    END GET_POINT_GEOM;
    I guess it has nothing with foreign key. There is something wrong with this function.
    By the way, a spatail index is built on this function. Does this make any differences on this point?

  • Rgding ORA-04091:table PURCHSE_DTL is mutating,trigger/function maynot c it

    I wrote a trigger 'TRG_PURCHASE_DTL' to update the stock table 'BRANCH_ITEM_STOCK' based on the DML actions perfomed on tables PURCHASE_DTL and ISSUE_DTL, but I am getting following error:-
    ORA-04091: table PURCHASE_DTL is mutating, trigger/function may not see it
    and the value of 'BRANCH_ITEM_STOCK.purchase_qty' is updated to 10 instead of 18.
    The table structure and data is given below:
    -- ============================================================
    -- Table: BRANCH_ITEM_STOCK
    -- ============================================================
    create table BRANCH_ITEM_STOCK
    BRANCH_CODE NUMBER(6) not null,
    ITEM_CODE NUMBER(6) not null,
    PURCHASE_QTY NUMBER(6) null ,
    RECEIPT_QTY NUMBER(6) null ,
    ISSUE_QTY NUMBER(6) null ,
    BALANCE_QTY NUMBER(6) null ,
    REMARKS VARCHAR2(100) null ,
    constraint PK_RA25_BRANCH_ITEM_STOCK primary key (BRANCH_CODE, ITEM_CODE)
    -- ============================================================
    -- Table: PURCHASE_MST
    -- ============================================================
    create table PURCHASE_MST
    BRANCH_CODE NUMBER(6) not null,
    PURCHASE_YR NUMBER(6) not null,
    PURCHASE_NO NUMBER(6) not null,
    PURCHASE_DT DATE not null,
    QUOTATION_NO NUMBER(6) not null,
    QUOTATION_YR NUMBER(4) not null,
    VENDOR_CODE NUMBER(6) not null,
    RECEIPT_NO VARCHAR2(25) null ,
    constraint PK_PURCHASE_HDR primary key (BRANCH_CODE, PURCHASE_YR, PURCHASE_NO)
    -- ============================================================
    -- Table: PURCHASE_DTL
    -- ============================================================
    create table PURCHASE_DTL
    BRANCH_CODE NUMBER(6) not null,
    PURCHASE_YR NUMBER(6) not null,
    PURCHASE_NO NUMBER(6) not null,
    REC_SNO NUMBER(6) not null,
    ITEM_CODE NUMBER(6) not null,
    ITEM_QTY NUMBER(6) not null,
    ITEM_PRICE NUMBER not null,
    ITEM_AMT NUMBER not null,
    constraint PK_PURCHASE_DTL primary key (BRANCH_CODE, PURCHASE_YR, PURCHASE_NO, REC_SNO)
    -- ============================================================
    -- Table: ISSUE_MST
    -- ============================================================
    create table ISSUE_HDR
    BRANCH_CODE NUMBER(6) not null,/* Issued from Branch*/
    ISSUE_YR NUMBER(6) not null,
    ISSUE_NO NUMBER(6) not null,
    ISSUE_DT DATE not null,
    ISSUED_BY VARCHAR2(15) not null,
    ISSUED_TO_BRANCH VARCHAR2(15) not null,
    ISSUE_STATUS NUMBER(6) null,
    constraint PK_ISSUE_HDR primary key (BRANCH_CODE, ISSUE_YR, ISSUE_NO)
    -- ============================================================
    -- Table: ISSUE_DTL
    -- ============================================================
    create table ISSUE_DTL
    BRANCH_CODE NUMBER(6) not null,
    ISSUE_YR NUMBER(6) not null,
    ISSUE_NO NUMBER(6) not null,
    REC_SNO VARCHAR2(25) not null,
    ITEM_CODE NUMBER(6) not null,
    ITEM_DTL VARCHAR2(400) null ,
    ITEM_QTY NUMBER(6) null ,
    RECEIPT_QTY NUMBER(6) null ,
    constraint PK_RA25_ISSUE_DTL primary key (BRANCH_CODE, ISSUE_YR, ISSUE_NO, REC_SNO)
    Assume that the Contents of PURCHASE_MST is as follows:
    SELECT branch_code, purchase_yr, purchase_no FROM PURCHASE_HDR;
    BRANCH_CODE PURCHASE_YR PURCHASE_NO     
    100          2008          1     
    100          2009          1     
    100          2009          2     
    Now I tried to insert follwing values to the PURCHASE_DTL table:
    insert into purchase_dtl (BRANCH_CODE,PURCHASE_YR,PURCHASE_NO,rec_sno,
    ITEM_CODE,item_QTY)
    Values (100,2008,1,1,4,5)
    insert into purchase_dtl (BRANCH_CODE,PURCHASE_YR,PURCHASE_NO,rec_sno,
    ITEM_CODE,item_QTY)
    Values (100,2009,1,1,4,2)
    insert into purchase_dtl (BRANCH_CODE,PURCHASE_YR,PURCHASE_NO,rec_sno,
    ITEM_CODE,item_QTY)
    Values (100,2009,2,1,4,6)
    commit
    Now Contents of table ' PURCHASE_DTL ' is as follows:
    BRANCH_CODE PURCHASE_YR PURCHASE_NO     REC_SNO ITEM_CODE     ITEM_QTY
    100          2008          1     1          4     5
    100          2009          1     1          4     2
    100          2009          2     1          4     6
    I want to write a trigger which will insert/update/delete data into/from BRANCH_ITEM_STOCK,
    so that the contents of column Purchase_qty of table BRANCH_ITEM_STOCK should be as follows:
    BRANCH_CODE     ITEM_CODE     PURCHASE_QTY     RECEIPT_QTY     ISSUE_QTY     BALANCE_QTY
    100          4          13          0          0          13
    [Note:  i.e BRANCH_ITEM_STOCK.PURCHASE_QTY = SUM(PURCHASE_DTL.item_qty) 
         where PURCHASE_DTL.branch_code=100
         AND PURCHASE_DTL.item_code=4
    Now run the following update statement.
    update purchase_dtl
    set item_qty= 10
    where BRANCH_code=100
    and purchase_yr in ( 2008) and purchase_no =1 and rec_sno = 1 AND item_code = 4
    commit
    Now the actual contents of column Purchase_qty of table BRANCH_ITEM_STOCK should be updated as follows:
    BRANCH_CODE     ITEM_CODE     PURCHASE_QTY     RECEIPT_QTY     ISSUE_QTY     BALANCE_QTY
    100          4          18          0          0          18
    But I am facing problem here. I am getting following error:-
    ORA-04091: table PURCHASE_DTL is mutating, trigger/function may not see it
    and the value of purchase qty is updated to 10 instead of 18
    Similarly if any issue of items happen (for eg:- issue_qty=2 to branch_code 200), then the purchase_qty =18,issue_qty=2 , balance_qty:=18-2=16 .
    So for branch_code 200 , receipt_qty = 2.
    Pls help me how to achieve the above .
    Source code which I tried is given below : (but confused at the end )..please help
    CREATE OR REPLACE TRIGGER trg_purchase_dtl
    BEFORE INSERT ON PURCHASE_DTL
    for each row
    declare
    -- local variables here
    l_qty number(6);
    l_cnt NUMBER;
    BEGIN
    BEGIN
    SELECT COUNT(*) into l_cnt
    FROM BRANCH_item_stock b
    WHERE b.BRANCH_code = :new.BRANCH_code
    AND b.item_code = :new.item_code ;
    dbms_output.put_line('1.after selet cnt= '||l_cnt);
    EXCEPTION when no_data_found then
    l_cnt := 0;
    dbms_output.put_line('2.in expt NDF selet cnt= '||l_cnt);
    null;
    END;
    IF INSERTING THEN
    dbms_output.put_line('3.before if ...going to insert ');
    IF l_cnt = 0 THEN
    dbms_output.put_line('hihhiii.......lcnt=0...item_code='||:old.item_code||'~l_qty='||l_qty);
    IF INSERTING THEN
         INSERT INTO BRANCH_ITEM_STOCK
    (BRANCH_code,Item_Code, PURCHASE_QTY,RECEIPT_QTY, issue_qty, balance_qty)
         VALUES(:NEW.BRANCH_code,:NEW.Item_Code, :NEW.ITEM_QTY,0, 0, 0);
    END IF;
    ELSIF l_cnt >0 THEN
    SELECT purchase_qty into l_qty
    FROM BRANCH_Item_Stock
    WHERE BRANCH_code = :new.BRANCH_code
    AND item_code = :new.item_code ;
    l_qty := l_qty + :NEW.ITEM_QTY;
    dbms_output.put_line('6.after selet qty= '||l_qty ||'~new qty='||:NEW.ITEM_QTY||'~old qty='||:OLD.ITEM_QTY);
    dbms_output.put_line('7.before update '||l_qty);
    -- IF INSERTING OR UPDATING THEN
    UPDATE BRANCH_ITEM_STOCK
              SET PURCHASE_QTY = l_qty
              WHERE BRANCH_code = :new.BRANCH_code
    AND item_code = :new.item_code ;
    dbms_output.put_line('8.after update= '||l_qty);
    --END IF;
    END IF;
    END IF; -- end of INSERTING
    -- END;
    --EXCEPTION WHEN DUP_VAL_ON_INDEX THEN
         IF UPDATING THEN
              dbms_output.put_line('9.if UPDATING...qty= '||l_qty ||'~new qty='||:NEW.ITEM_QTY||'~old qty='||:OLD.ITEM_QTY);
    BEGIN
    dbms_output.put_line('~old unotcode='||:old.BRANCH_code||'~old.item_code='||:OLD.ITEM_CODE||'~old itemqty='||:old.item_qty);
    dbms_output.put_line('~new unotcode='||:new.BRANCH_code||'~new.item_code='||:new.ITEM_CODE||'~new itemqty='||:new.item_qty);
    SELECT NVL(SUM(item_qty), 0) into l_qty
         FROM Ra25_Purchase_Dtl
         WHERE BRANCH_code IN ( :old.BRANCH_code )
         AND item_code in ( :old.item_code)
         AND item_qty <> :old.item_code ;
    EXCEPTION WHEN OTHERS THEN
    dbms_output.put_line('10.in EWO'||sqlerrm);
    END;
    --l_qty := l_qty + :NEW.ITEM_QTY;         
    dbms_output.put_line('11.after selet qty= '||l_qty ||'~new qty='||:NEW.ITEM_QTY||'~old qty='||:OLD.ITEM_QTY);
         UPDATE BRANCH_ITEM_STOCK
              SET PURCHASE_QTY = l_qty      --:new.item_qty
              WHERE BRANCH_code = :old.BRANCH_code
              AND item_code = :old.item_code ;
              dbms_output.put_line('13.after update ');
         END IF;
    IF DELETING THEN
    DELETE FROM BRANCH_ITEM_STOCK
    WHERE BRANCH_CODE = :OLD.BRANCH_code
    AND ITEM_CODe = :OLD.item_code;
    END IF;
    end trg_purchase_dtl;
    Please help me how to resolve this problem asap.
    -------------------------------------------------------------------------------------------------------------------------------------------------

    Hi,
    Welcome to the forum!
    See this thread [Avoiding Mutating Tables|http://asktom.oracle.com/tkyte/Mutate/index.html]
    Tip: to preserve formatted code enclose it between {noformat}{noformat} tags (start and end tags are the same) :)
    Thank you for posting DDL and DML of basic data, all people that post should follow this approach.
    Regards,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

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

    I create this trigger:
    CREATE OR REPLACE TRIGGER pr_test
    after insert ON AM
    FOR EACH ROW
    declare
    appo_pr varchar2(64):= null;
    BEGIN
    select name
    into appo_pr
    from AS
    where AS_ID=:new.AS_ID;
    insert into AM (name) values (appo_pr);
    END pr_test;
    I insert before a new AS_ID and name in tab AS but when I insert a new record in tab AM I get this error:
    ORA-04091: table AM is mutating, trigger/function may not see it
    ORA-06512: at PR_TEST", line 11
    ORA-04088: error during execution of trigger PR_TEST'
    I'd like to create a trigger that when I insert a new record in AM It verify the value in col name of AS and insert this value in col name of AM.
    What I wrong in this trigger??
    How can I modify it??
    Thanks
    Raf

    Try this:
    CREATE OR REPLACE TRIGGER pr_test
      before insert ON AM
      FOR EACH ROW
    declare
      appo_pr AS.name%TYPE;
    BEGIN
      select name
      into   appo_pr
      from   AS
      where  AS_ID = :new.AS_ID;
      :new.name = appo_pr;
    END pr_test;

Maybe you are looking for

  • Message processing failed, FTP Receiver Adapter error...

    Hello all, We have a Idoc to File(FTP) scenario using PI. When PI try to send the file out to the FTP site, we get the following message in the communication channel monitoring and the file never reach the FTP site: Message processing failed. Cause:

  • Aperture with referenced library on a terastation

    I was experiencing a problem similar (or identical) to the one discussed in this post (http://discussions.apple.com/message.jspa?messageID=6695612&tstart=0) and made some head-way on debugging it. Since I have a few more data points, I'm creating a t

  • Selection screen - Background submit using JOB_SUBMIT

    Hello friends,                   I am using 2 reports , say report 1(R1) and report 2(R2). I am getting a particular value in selection screen from R2 and based on that value I am submitting the report R1 in background using JOB_OPEN,JOB_SUBMITand JO

  • Hierarchial Queries and Redo log files

    Hi, I'm running a hierarchial query (start with, connect by prior, etc.). The query takes a couple of minutes and apparently is filling up the archive files (I assume it comes from the redo log files). Question: 1. Does it make sense that a hierarchi

  • AM010 with general billing interface and CPD customer

    Hi all I'm trying to create a SD invoices with the general billing interfaces. All the partner are One-time customers. In simulation launch no error is generates, but when i search to create the final posting, the AM010 "address doesn't exist" create