Mutation in oracle

Can any one tell me what in mutation in oracle database??
I m new to this concept....
So please if u can help me on this??
Thanx in advance...

http://asktom.oracle.com/tkyte/Mutate/
Greetings,
Sim

Similar Messages

  • 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

  • Can anyone kindly explain what mutative triggers are in Oracle?

    hi
    Can anyone kindly explain what mutative triggers are in Oracle with example?
    what is frag in oracle?

    Oracle raises the mutating table error to protect you from building in-deterministic software.
    Let’s explain that with a very simple example. Here’s a simple EMP-table:
    ENAME      SAL
    ======     ====
    SMITH      6000
    JONES      4000Let’s suppose you have a business rule that dictates that the average salary is not allowed to exceed 5000. Which is true for above EMP-table (avg. SAL is exactly 5000).
    And you have (erroneously) built after-row triggers (insert and update) to verify this business rule. In your row trigger you compute the average salary, check it’s value and if it’s more than 5000 you raise an application error.
    Now you issue following DML-statement, to increase the salary of employees earning less than the average salary, and to decrease the salary of employees earning more than the average salary.
    Update EMP
    Set SAL = SAL + ((select avg(SAL) from EMP) – SAL)/2;The end result of this update is:
    ENAME      SAL
    ======     ====
    SMITH      5500
    JONES      4500Note that the business rule is still OK: the average salary still doesn’t exceed 5000. But what happens inside your row-trigger, that has a query on the EMP-table?
    Let’s assume the rows are changed in the order I displayed them above. The first time your row trigger fires it sees this table:
    ENAME      SAL
    ======     ====
    SMITH      5500
    JONES      4000The row trigger computes the average and sees that it is not more than 5000, so it does not raise the application error. The second time your row trigger fires it sees the end result.
    ENAME      SAL
    ======     ====
    SMITH      5500
    JONES      4500For which we already concluded that the row-trigger will not raise the application error.
    But what happens if Oracle in it’s infinite wisdom decides to process the rows in the other order? The first time your row trigger executes it sees this table:
    ENAME      SAL
    ======     ====
    SMITH      6000
    JONES      4500And now the row-trigger concludes that the average salary exceeds 5000 and your code raises the application error.
    Presto. You have just implemented indeterministic software. Sometimes it will work, and sometimes it will not work.
    Why? Because you are seeing an intermediate snapshot of the EMP-table, that you really should not be seeing (that is: querying).
    This is why Oracle prevents you from querying the table that is currently being mutated inside row-triggers (i.e. DML is executed against it).
    It’s just to protect you against yourself.
    (PS1. Note that this issue doesn't happen inside statement-triggers)
    (PS2. This also shows that mutating table error is really only relevant when DML-statements affect more that one row.)
    Edited by: Toon Koppelaars on Apr 26, 2010 11:29 AM

  • Problem with trigger and mutating table

    Hello,
    I have a problem with the following trigger. Everytime it starts I got an error message:
    ORA-04091: table ccq_test.QW_QUALIFIER is mutating, trigger/function may not see it
    ORA-06512: at "QW_AFTER_UPDATE_ALL", line 3
    ORA-06512: at "QW_AFTER_UPDATE_ALL", line 10
    ORA-04088: error during execution of trigger 'QW_AFTER_UPDATE_ALL'
    Here is the trigger:
    CREATE OR REPLACE TRIGGER qw_after_update_all
    AFTER UPDATE ON ccq_test.QW_QUALIFIER FOR EACH ROW
    DECLARE
         CURSOR c1 IS SELECT id AS mx FROM QW_QUALIFIER_LOG WHERE msgid = :NEW.msgid AND messagedate BETWEEN SYSDATE - (1 / (24 * 60 * 6)) AND SYSDATE AND transfer = 1;
         CURSOR c_qwprod IS SELECT value FROM ccq_test.QW_QUALIFIER WHERE msgid = :NEW.msgid AND name = 'product';
         CURSOR c_qwgesch IS SELECT value FROM ccq_test.QW_QUALIFIER WHERE msgid = :NEW.msgid AND name = 'geschaeftsfall';
         qw_rec c1%ROWTYPE;
         qw_prod c_qwprod%ROWTYPE;
         qw_gesch c_qwgesch%ROWTYPE;
    BEGIN
    OPEN c1;
    OPEN c_qwprod;
    OPEN c_qwgesch;
         FETCH c1 INTO qw_rec;
         FETCH c_qwprod INTO qw_prod;
         FETCH c_qwgesch INTO qw_gesch;
         IF c1%NOTFOUND THEN
              IF (:NEW.name = 'product') THEN
                   INSERT INTO QW_QUALIFIER_LOG VALUES (QW_QUALIFIER_LOG_SEQ.NEXTVAL, :NEW.msgid, :NEW.value, qw_gesch.value, SYSDATE, 1);
              ELSE
              INSERT INTO QW_QUALIFIER_LOG VALUES (QW_QUALIFIER_LOG_SEQ.NEXTVAL, :NEW.msgid, qw_prod.value, :NEW.value, SYSDATE, 1);
         END IF;
         ELSE
              IF (:NEW.name = 'product') THEN
                   UPDATE QW_QUALIFIER_LOG SET product=:NEW.value, messagedate=SYSDATE WHERE id = qw_rec.mx;
              ELSE
                   UPDATE QW_QUALIFIER_LOG SET geschaeftsfall=:NEW.value, messagedate=SYSDATE WHERE id = qw_rec.mx;
         END IF;
         END IF;
    CLOSE c1;     
    END;
    Can anyone help me?

    You are trying to lookup data from qw_qualifier you are currently modifying. You could see the data in a inconsistent way and Oracle is protecting you from it.
    You could read here about how to program around this problem.
    But: your table design seems questionable. You have two records for qw_qualifier and you are trying to log it into one qw_qualifier_log record. Maybe you could fix that, and the need for querying the same table as you are updating is removed.
    Regards,
    Rob.

  • Problems with Oracle 11g XE R2

    Hi guys,
    I've got a problem and try'n to solve it for abt a week now and tried many solutions.
    My enviroment:
    Windows 7 Professional SP 1 64-Bit
    AMD Phenom II x4 940 @3.0 GH
    4 GB RAM (In Usage while installing 40%)
    Windows-Firewall is activated (but oracle.exe and lstnr.exe are configured as exception)
    avast! Free Antivirus Version 2014.9.0.2018
    Installation (both times with same outcome):
    Installed O 11g XE 64-Bit in two different ways:
    User I was logged in with is in Admingroup
    Started installation via rightclick with administrationprivileges
    I activated the administrators account and logged in with adminprivileges.
    After that I've installed the 11g XE 64 bit
    between both steps I cleaned everything up and restarted my system, registry was empty too and folder was deleted manually
    at first I get this problem: Windows cannot find "http://127.0.0.1:%HTTPPORT%/apex/f?p=4950"
    -> Manually changing %HTTPORT% to 8080
    --> now I could doubleclick the shortcut, Firefox/IE/Chrome opens but 404 not Found-Error is returned
    - OracleServiceXE, XracleXETNListener both are running
    [code]
    C:\Windows\system32>lsnrctl status
    LSNRCTL for 64-bit Windows: Version 11.2.0.2.0 - Production on 04-NOV-2014 18:02
    :56
    Copyright (c) 1991, 2014, Oracle.  All rights reserved.
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
    TNS-12541: TNS:no listener
    TNS-12560: TNS:protocol adapter error
      TNS-00511: No listener
       64-bit Windows Error: 2: No such file or directory
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=D³rsinKurt-PC)(PORT=1521
    STATUS of the LISTENER
    Alias                     LISTENER
    Version                   TNSLSNR for 64-bit Windows: Version 11.2.0.2.0 - Produ
    ction
    Start Date                04-NOV-2014 13:53:50
    Uptime                    0 days 4 hr. 9 min. 9 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Listener Log File         C:\oraclexe\app\oracle\diag\tnslsnr\D³rsinKurt-PC\list
    ener\alert\log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=D³rsinKurt-PC)(PORT=1521)))
    The listener supports no services
    The command completed successfully
    [/code]
    so Listenerservice is up and running but I cant find the http 8080-Service with netstat -a
    so I started investigating a bit more:
    Registryfolder: HK_LOCAL_MACHINE\SOFTWARE\ORACLE is installed
    following subdirectories are installed: KEY_XE, ODP.NET, OracleMTSRecoveryService
    What I tried (both ways, starting with and without adminstrationprivileges):
    I created two new DWORD-Values in KEY_XE ORACLE_SID_AUTOSTART and -SHUTDOWN both with the value True and stopped and started the services, nothing changes.
    Inserted both users (Administrator and normal User) in ORA_DBA-Group, nothing changes, even tried to turn it off and on again
    wanted to connect to sqlplus via console:
    C:\Windows\system32>sqlplus system
    SQL*Plus: Release 11.2.0.2.0 Production on Di Nov 4 18:09:21 2014
    Copyright (c) 1982, 2014, Oracle.  All rights reserved.
    Enter password:
    ERROR:
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    Process ID: 0
    Session ID: 0 Serial number: 0
    Enter user-name:
    when I start the sqlplus-prompt directly and write the command startup I get the following msg: ORA-01031: insufficient privileges
    I looked into the ORA_BASE-Folder and looked at the oradat folder, it contains a XE-Folder which is empty, the admin-folder contains: XE/ and adump, dpdump and pfile, all three are empty (what does this mean? No DB at all created?)
    I watched the ORA_HOME-Folder and found initXE.ora, oradba.exe, oradim and PWDXE.ora
    I looked into the oradim.txt-Log:
    Tue Nov 04 11:21:17 2014
    C:\oraclexe\app\oracle\product\11.2.0\server\bin\oradim.exe -shutdown -sid xe -usrpwd * -shutmode immediate -log oradim.log
    Tue Nov 04 11:21:55 2014
    ORA-01012: not logged on
    Tue Nov 04 11:23:01 2014
    C:\oraclexe\app\oracle\product\11.2.0\server\bin\oradim.exe -startup -sid xe -usrpwd *  -log oradim.log -nocheck 0
    Tue Nov 04 11:23:38 2014
    ORA-01078: failure in processing system parameters
    ORA-01565: error in identifying file 'C:\oraclexe\app\oracle\product\11.2.0\server\dbs/spfileXE.ora'
    ORA-27041: unable to open file
    OSD-04002: unable to open file
    O/S-Error: (OS 2) Das System kann die angegebene Datei nicht finden.
    --> bingo, 1st Issue: there is no spfileXE.ora, how can I create this? plus in the dbs-folder there is only a init.ora and no initXE.ora?
    Looked into the log-Folder 5 files starting with clscX.txt (probably after every systemreboot? containing the following:
    Oracle Database 11g Clusterware Release 11.2.0.2.0 - Production Copyright 1996, 2010 Oracle. All rights reserved.
    2014-11-04 13:53:52.197: [ default][5576]ut_read_reg:2:ocr registry key SOFTWARE\Oracle\olr cannot be opened. error 2
    [    CLSE][5576]clse_get_crs_home: Error retrieving OLR configuration [0] [Error opening olr registry key. The system couldn't find the file.
    -> Systemlanguage is german, so I've translated the german parts, maybe there was smth lost in translation
    --> 2nd Issue: Is there any regkey missing?
    further I watched the folder ORACLE_HOME /server/config/home cloesly:
    cloneDBCreation:
    SQL> Create controlfile reuse set database "XE"
      2  MAXINSTANCES 8
      3  MAXLOGHISTORY 1
      4  MAXLOGFILES 16
      5  MAXLOGMEMBERS 3
      6  MAXDATAFILES 100
      7  Datafile
      8  'C:\oraclexe\app\oracle\oradata\XE\system.dbf',
      9  'C:\oraclexe\app\oracle\oradata\XE\undotbs1.dbf',
    10  'C:\oraclexe\app\oracle\oradata\XE\sysaux.dbf',
    11  'C:\oraclexe\app\oracle\oradata\XE\users.dbf'
    12  LOGFILE
    13  GROUP 1 SIZE 51200K,
    14  GROUP 2 SIZE 51200K,
    15  RESETLOGS;
    SP2-0640: Not connected
    SQL> exec dbms_backup_restore.zerodbid(0);
    SP2-0640: Not connected
    SP2-0641: "EXECUTE" requires connection to server
    SQL> shutdown immediate;
    ORA-01012: not logged on
    SQL> startup nomount pfile="C:\oraclexe\app\oracle\product\11.2.0\server\config\scripts\initXETemp.ora";
    ORA-01031: insufficient privileges
    CloneRmanRestore:
    SQL> startup nomount pfile="C:\oraclexe\app\oracle\product\11.2.0\server\config\scripts\init.ora";
    ORA-01031: insufficient privileges
    SQL> @C:\oraclexe\app\oracle\product\11.2.0\server\config\scripts\rmanRestoreDatafiles.sql;
    SQL> set echo off;
    SP2-0640: Not connected
    SP2-0640: Not connected
    SP2-0640: Not connected
    ERROR:
    ORA-01031: insufficient privileges
    SQL> spool C:\oraclexe\app\oracle\product\11.2.0\server\config\log\cloneDBCreation.log
    PostDBCreation:
    QL> connect "SYS"/"********" as SYSDBA
    ERROR:
    ORA-01031: insufficient privileges
    SQL> set echo on
    SQL> //create or replace directory DB_BACKUPS as 'C:\oraclexe\app\oracle\fast_recovery_area';
    SP2-0103: Nothing in SQL buffer to run.
    SQL> begin
      2      dbms_xdb.sethttpport('8080');
      3      dbms_xdb.setftpport('0');
      4  end;
      5  /
    SP2-0640: Not connected
    SQL> create spfile='C:\oraclexe\app\oracle\product\11.2.0\server\dbs/spfileXE.ora' FROM pfile='C:\oraclexe\app\oracle\product\11.2.0\server\config\scripts\init.ora';
    SP2-0640: Not connected
    SQL> shutdown immediate;
    ORA-01012: not logged on
    SQL> connect "SYS"/"&&sysPassword" as SYSDBA
    ERROR:
    ORA-01031: insufficient privileges
    SQL> @C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\dbmssml.sql;
    SP2-0310: unable to open file "C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\dbmssml.sql"
    SQL> @C:\oraclexe\app\oracle\product\11.2.0\server\rdbms\admin\dbmsclr.plb;
    SQL> DROP PUBLIC DATABASE LINK DBMS_CLRDBLINK;
    SP2-0640: Not connected
    SQL> CREATE PUBLIC DATABASE LINK DBMS_CLRDBLINK USING 'ORACLR_CONNECTION_DATA';
    SP2-0640: Not connected
    SQL> CREATE OR REPLACE LIBRARY ORACLECLR_LIB wrapped
      2  a000000
      3  1
      4  abcd
      5  abcd
      6  abcd
      7  abcd
      8  abcd
      9  abcd
    10  abcd
    11  abcd
    12  abcd
    13  abcd
    14  abcd
    15  abcd
    16  abcd
    17  abcd
    18  abcd
    19  16
    20  51 8d
    21  L/XXXXXXXXXX...
    22  XXXXXXX...
    23 
    24  /
    SP2-0640: Not connected
    SQL> DROP TYPE DBMS_CLRParamTable;
    SP2-0640: Not connected
    SQL> DROP TYPE DBMS_CLRType;
    SP2-0640: Not connected
    SQL> CREATE OR REPLACE TYPE DBMS_CLRType wrapped
    XE :
    Instance created.
    So hopefully thats enough Information
    thank you in advance
    Dürsin Kurt

    OK guys I've found it out:
    Problem was, the XE.bat-Script couldn't add me to the ORA_DBA-Group.
    Reason: my Computername and my username, both had a vowel mutation "ü".
    Reason it didn't work at my business-laptop too, both have my "Ü" in the username
    solved!

  • Mutating tirgger issue while setting a value

    I have a table and records as below:
    CREATE TABLE set_time
    NUM NUMBER,
    ID NUMBER,
    SET_VALUE CHAR(1 BYTE),
    D_TIME DATE
    Insert into SET_TIME (NUM, ID) Values (1, 1);
    Insert into SET_TIME (NUM, ID) Values (2, 1);
    Insert into SET_TIME (NUM, ID) Values (3, 1);
    Insert into SET_TIME (NUM, ID) Values (4, 1);
    Insert into SET_TIME (NUM, ID) Values (5, 1);
    Insert into SET_TIME (NUM, ID) Values (1, 2);
    Insert into SET_TIME (NUM, ID) Values (2, 2);
    Insert into SET_TIME (NUM, ID) Values (3, 2);
    I need a trigger,whenever all the set_values for a particular id is set to 'Y', I need to update the column d_time as sys_date.For that I wrote below trigger
    CREATE OR REPLACE TRIGGER set_time_trigger
    before update
    ON set_time for each row
    DECLARE
    v_count number;
    BEGIN
    if :new.set_value = 'Y' then
    select 1 into v_count
    from dual
    where exists ( select null
    from set_time
    where ID = :new.id
    AND ( set_value != 'Y'));
    if v_count is null then
    update set_time
    set d_time = sysdate where ID =:new.id;
    end if;
    end if;
    end;
    But while executing the below statement:
    update set_time set set_value ='Y' where id = 1;
    I am gettign the follwoing error:
    ORA-04091: table SET_TIME is mutating, trigger/function may not see it
    ORA-06512: at "SET_TIME_TRIGGER", line 13
    ORA-04088: error during execution of trigger 'SET_TIME_TRIGGER'
    Is there anyway that I can achieve this?. I am using Oracle 11G.
    Thanks in Advance

    1) If D_TIME depends on the data that is set for multiple rows in your table, you have a normalization problem. It sounds like you need to rethink your data model and break out the ID column into a separate table.
    2) A row-level trigger cannot generally query the table on which it is defined. So you generally cannot code a row-level trigger that would query the data in other rows of the table. You could define a package which had a collection of ID values, create a before update statement-level trigger that initialized the collection, create a row-level trigger that inserted the :new.id into this packaged collection, and create an after update statement-level trigger that read the data from the collection, queried the table, and did the updates as appropriate. That's a lot of work to go through and a lot of complexity to introduce.
    Additionally, this sort of trigger-based approach does not generally work in a multiuser environment. If Session A is inserting a new row with an ID of 1 and a SET_TIME of N at the same time that Session B is setting the SET_TIME of all the committed rows with an ID of 1 to Y, the trigger in Session B can update the D_TIME before session A commits its data leaving you with a case where D_TIME is set and not every row with an ID of 1 has a SET_TIME of Y.
    Justin

  • Mutating Trigger error while updating table

    Hi Guys,
    I am updating one table and after trigger also fire at the same time. Now, I want to avoid mutating trigger error. Can any one help me on this.
    Thanks in advance!
    Regards,
    -LRK

    You'll have to read these articles first, they explain what's the problem and how to deal with it:
    http://www.oracle-base.com/articles/9i/MutatingTableExceptions.php
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936
    but, as Saubhik already said, using Oracle's AUDIT functionality would be the way to go.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4007.htm
    Using an autonomous transaction can result in corrupted data or unexpected errors, stay away from them if you want to use them in order to bypass/hide your mutating table error.

  • What is the Standard Syllabus for Oracle Apps Technical

    Dear Members I have studied Oracle Apps Technical 11i in this First I learned
    SQL ( Different Languages like DDL, DML, DCL, TCL, DQL, Operator, Functions, Constraints, Joins, Sub Queries, Locks on Tables, Synonyms, Sequences, Index, Views)
    PL/SQL (Pl/Sql Attributes, Control Statements (If, If Else, else if, Loop, for loop) Exceptions, Cursor & its attributes (normal Parameter cursor, Ref cursor), Procedures( In, Out, IN and Out, IN OUT), Functions ( In, Out, IN OUt), Packages, Triggers
    SQL* Loader, UTL File Packages,
    Oracle Apps Technical
    Introductions to ERP ( definition of ERP, overview of popular ERP's, comparision of oracle apps with other ERP's, types of roles, types of projects, AIM documentations Standard, Oracles Apps Architecture, Using Toad),
    AOL ( Who Columns, viewing responsibilities, menu construction) ,
    Application Development( Defining concurrent programs, concurrent program with parameters, working with multiple concurrent programs, concurrent programs incompatibilities, creating request set procedure registrations, value set) ,
    Report Registration( Report development, report registration, parametric report registration, report with repeating frames),
    Module Overview( Inventory Module flow with base tables, account payable module flow with base tables, account receivable module with base tables, order management module with base tables, pruchase order module with base tables, General ledger with base tables),
    Forms Registration ( pll files Downloading,Template FMB, Form Development using Templates, Form Registration process, ),
    Interfaces ( Intro to interfaces, outbound interafaces - Using Utl file package, Inbound interfaces Using Sql Loader tool),
    Conversions ( Overview on conversions, differences between interfaces and conversions, working with staging tables script, developing validation package, standard to be follow in conversions),
    Flex Fields( Types of Flex Fields, Description Flex Fields, Key Flex Fields),
    XML Publisher (Intro to XML Publisher, Generating XML File Using Report, Creating Templates, Creating Data Definitions
    I have learned only Inventory Module in Conversion, Interfaces, Reports, Forms ( other module like application developer, system administrator, XML Publisher)
    I have learned Item Import Project In Conversions, On Hand Quantity In Interfaces, Stock Expiration Report using Reports, XML Publisher)
    Why i Got this doubt because I attend interview they were asking different questions like this which My faculty didn't teach
    What are the receipt tables?
    What is invoice table name?
    API Name for conversion
    What is external table
    What is Pragma
    How many types of item available
    Mutating error
    P2P cycle
    is all the above belongs to apps Technical only I asked my faculty he said its functional who is correct faculty or interviewer
    Please help me in this regard
    Edited by: 969372 on Feb 1, 2013 12:22 PM
    Edited by: 969372 on Feb 1, 2013 12:22 PM

    Hi,
    Why i Got this doubt because I attend interview they were asking different questions like this which My faculty didn't teach
    What are the receipt tables?
    What is invoice table name?
    API Name for conversion
    What is external table
    What is Pragma
    How many types of item available
    Mutating error
    P2P cycle
    is all the above belongs to apps Technical only I asked my faculty he said its functional who is correct faculty or interviewer
    Please help me in this regardWhat all you have studied is basics. And in the institutes they only teach you 5% of actual work, Yes only 5%. They can not teach the whole 5 years learning just in few classes.
    In real time When you are working as a technical consultant, you get to speak to functional consultants a lot of time for developing reports, customization, creating custom forms.... So thats why the interviewer has asked a mixture of both technical and functional.
    The questions they asked also depends on the number of years experience you have in the resume ;).
    How ever you can gain more knowledge from blogs and forums like this.
    I will point you to few of them
    Your first step should be reading all the documents related to technical filed from the following link.
    http://docs.oracle.com/cd/B53825_08/current/html/docset.html
    Then read atleast 10 to 15 real time issues related to your field from forums like this.
    and read posts from oracle apps technical gurus like Anil Passi,
    http://oracle.anilpassi.com/basic-concepts-list-of-useful-oracle-apps-articles-2.html
    and links to all the technical blogs can be found at
    http://oracleappsexperience.blogspot.com/2010/02/my-favourite-links.html
    Best of luck and you will get a job soon.
    Thanks

  • 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

  • Best way to deal with Mutating table exception with Row Level Triggers

    Hello,
    It seems to be that the best way to deal with Mutating Table exception(s) is to have to put all the trigger code in a package & use it in conjunction with a Statement level trigger .
    This sounds quite cumbersome to me . I wonder is there any alternative to dealing with Mutating table exceptions ?
    With Regards

    AskTom has a good article about this,
    http://asktom.oracle.com/tkyte/Mutate/index.html

  • Triggers on tables in the Oracle BAM DataObjects

    Hi there.
    I am using Monitor Express in Oracle BAM 11.1.1.4 (PS3) and the field LATEST from dataobject BIdefault_composite_component is working as desired.
    I want to use the same solution in Oracle BAM 11.1.1.3, but the field "_LATEST" was not filled automatically as other fields.
    So, I tried to write a trigger to update _LATEST manually, but when I added a new register, using BAM Architect, an error message was shown:
    BAM-01265: An error (ORA-04091: table DEV_ORABAM._BI_DEFAULT_BPMFormalisticaBND is mutating, trigger/function may not see it ORA-06512: at "DEV_ORABAM.ATUALIZALATEST", line 4 ORA-04088: error during execution of trigger 'DEV_ORABAM.ATUALIZALATEST' ) has occurred in the Active Data Cache storage system.
    But bam_server.log don't show nothing related to this error.
    Do I can not add triggers to BAM's dataobjects?
    Thanks.
    Luciano

    Problem solved.
    I had formulated my trigger incorrectly (I rewrote it after to see http://www.techonthenet.com/oracle/errors/ora04091.php).
    After to fix my trigger, i had the same result (or similar) that was expected with PS3 installed: atualization of field LATEST of the dataobject BIDEFAULT_...
    Luciano

  • Need Urgent Help with trigger in Oracle 10g

    Hello frd,
    I am working on my DBMS Project in VB 6.0 that is Tollbooth management system
    i have to insert one trigger for my project so i had decided to insert time trigger.
    I have total 3 table UserLogin, Vehice and Vehicle_Data
    the 3rd table Vehicle data contain the following fields
    Vehicle_Type, Vehicle_No, Tax_Time, Source, Destination and Tax
    Now i had done coding for tax when you select Vehicle Type, Source and Destination the Tax Field will automatically fillup and all the data will Saved in Oracle table but now my problem is that i want to create trigger for Tax_Time column When any new data inserted current time will stored in that column
    I had create one but it gives error
    create trigger time after insert on vehicle_Data
    for each row
    begin
    insert into Vehicle_Data(Tax_Time) values(to_char(sysdate, 'HH:MI:SSAM DD_MON_YYYY'));
    end;
    Note: I am Using VB 6.0 and Oracle 10g Express Edition

    I had create one but it gives errorWelcome to the forum and many many thanks for not posting the full error message, that is really helpful, since we're all a 100% sure what's going on now (yes, that was ironic ;) ).
    Let me guess: a mutating table error?
    Read:
    http://www.oracle-base.com/articles/9i/MutatingTableExceptions.php
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936
    But before that, actually you should read:
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html

  • Mutating table

    Hello,
    I have a table with srce_id,c_code and l_c_code. when ever data is uploaded into w_ty_e_ap table c_code value has to be copied to l_c_code based on srce_id.Input file has blank data for l_c_code.When I have written the below trigger I am getting:
    ORA-04091: table w_ty_e_ap is mutating, trigger/function may not see it
    Can you please advise me,
    Cheers,
    PSK
    CREATE OR REPLACE TRIGGER SA_TR_CO_CE_SM
    after INSERT
    ON w_ty_e_ap
    FOR EACH row
    DECLARE
    vno NUMBER;
    CURSOR c1
    IS
    SELECT c_code
    from w_ty_e_ap
    where srce_id=:new.srce_id
    for update of c_code;
    BEGIN
    open c1;
    loop
    fetch c1 into vno;
    if c1%notfound then
    VNO := 9999;
    else
    UPDATE w_ty_e_ap
    SET l_c_code = vno
    WHERE CURRENT OF c1;
    end if;
    end loop;
    close c1;
    END;
    /

    Hi ,
    I also paste the following proposed by Oracle .......about mutating tables
    A mutating table is a table that is being modified by an UPDATE, DELETE, or INSERT statement, or a table that might be updated by the effects of a DELETE CASCADE constraint.
    The session that issued the triggering statement cannot query or modify a mutating table. This restriction prevents a trigger from seeing an inconsistent set of data.
    This restriction applies to all triggers that use the FOR EACH ROW clause. Views being modified in INSTEAD OF triggers are not considered mutating.
    When a trigger encounters a mutating table, a runtime error occurs, the effects of the trigger body and triggering statement are rolled back, and control is returned to the user or application.
    Consider the following trigger:
    CREATE OR REPLACE TRIGGER Emp_count
    AFTER DELETE ON Emp_tab
    FOR EACH ROW
    DECLARE
        n INTEGER;
    BEGIN
        SELECT COUNT(*) INTO n FROM Emp_tab;
        DBMS_OUTPUT.PUT_LINE(' There are now ' || n ||
            ' employees.');
    END;
    If the following SQL statement is entered:
    DELETE FROM Emp_tab WHERE Empno = 7499;
    An error is returned because the table is mutating when the row is deleted:
    ORA-04091: table SCOTT.Emp_tab is mutating, trigger/function may not see it
    If you delete the line "FOR EACH ROW" from the trigger, it becomes a statement trigger which is not subject to this restriction, and the trigger.
    If you need to update a mutating table, you could bypass these restrictions by using a temporary table, a PL/SQL table, or a package variable. For example, in place of a single AFTER row trigger that updates the original table, resulting in a mutating table error, you might use two triggers—an AFTER row trigger that updates a temporary table, and an AFTER statement trigger that updates the original table with the values from the temporary table.
    Declarative integrity constraints are checked at various times with respect to row triggers.
    Because declarative referential integrity constraints are not supported between tables on different nodes of a distributed database, the mutating table restrictions do not apply to triggers that access remote nodes. These restrictions are also not enforced among tables in the same database that are connected by loop-back database links. A loop-back database link makes a local table appear remote by defining an Oracle Net path back to the database that contains the link.Regards,
    Simon

  • Mutating table and row state - this was unexpected

    So, I learned in a class about 3 years ago to expect the following
    SQL> create table p (pk number primary key);
    Table created.
    SQL> create table c (fk number references p(pk));
    Table created.
    SQL> create or replace trigger t_insrt
      2  before insert on p
      3  for each row
      4  begin
      5   insert into c values (:new.pk);
      6  end;
      7  /
    Trigger created.
    SQL> insert into p values (1);
    insert into p values (1)
    ERROR at line 1:
    ORA-02291: integrity constraint (FORBESC.SYS_C00169150) violated - parent key
    not found
    ORA-06512: at "FORBESC.T_INSRT", line 2
    ORA-04088: error during execution of trigger 'FORBESC.T_INSRT'and so it led me to think that replicating ON MODIFY PARENT - MODIFY CHILD functionality wouldn't work in a BEFORE ROW trigger, but it does
    SQL> drop trigger t_insrt;
    Trigger dropped.
    SQL> create or replace trigger p_updt
      2  before update on p
      3  for each row
      4  begin
      5   update c
      6   set fk = :new.pk
      7   where fk = :old.pk;
      8  end;
      9  /
    Trigger created.
    SQL> insert into p values (1);
    1 row created.
    SQL> insert into c values (1);
    1 row created.
    SQL> select * from c;
            FK
             1
    SQL> update p
      2  set pk = 2
      3  where pk = 1;
    1 row updated.
    SQL> select * from c;
            FK
             2Why would the first scenario fail while the second succeeds? The update seems prone to a parent record also not existing, at least not by the BEFORE ROW trigger.
    ---=Chuck

    < mutating table and row state >
    BTW, you don't seem to have run into the mutating table error though 2 other threads today are also about it. You have a constraint violation, a different thing entirely.
    I believe the second scenario works because you're neatly avoiding the error of the first. The error "ORA-02291: integrity constraint (FORBESC.SYS_C00169150) violated" means that on insert Oracle is looking up the value you're trying to insert, not finding it, and raising an error. With the before trigger you are taking the assigned value from the insert, updating the parent to it, so that on actual insert when the check happens the value is there due to the update.
    I'm not convinced this is a good idea because any on-the-fly approach to data entry needs to be examined carefully.

  • Triggers from sybase to oracle giving problem-------urgent please

    all the Triggers are got converted to AFTER INSERT/UPDATE/DELETE TRIGGERS IN migration workbench...and almost all are been checking the existence of records in the table ie.,primary key check (existence of record) which if i turn them to BEFORE INSERT is becoming a MUTATING ERROR.
    and one more thing the "count(*) from inserted" in sybase equivalent is not there in oracle how to solve this problem?????
    if (select count(*) from attr_val av, inserted i
              where av.class_cd = i.class_cd
              and av.attr_cd = i.attr_cd
              and av.attr_val = i.attr_val) >
              ( select count(*) from inserted )
    for (select count(*) from inserted) is getting converted to select count(*) from dual
    Thanks in advance,
    srinivas.

    all the Triggers are got converted to AFTER INSERT/UPDATE/DELETE TRIGGERS IN migration workbench...and almost all are been checking the existence of records in the table ie.,primary key check (existence of record) which if i turn them to BEFORE INSERT is becoming a MUTATING ERROR.
    and one more thing the "count(*) from inserted" in sybase equivalent is not there in oracle how to solve this problem?????
    if (select count(*) from attr_val av, inserted i
              where av.class_cd = i.class_cd
              and av.attr_cd = i.attr_cd
              and av.attr_val = i.attr_val) >
              ( select count(*) from inserted )
    for (select count(*) from inserted) is getting converted to select count(*) from dual
    Thanks in advance,
    srinivas.

Maybe you are looking for

  • IPod touches don't connect to home network

    For some time, the two iPod touches in our household have had trouble connecting to our home network.  There have been no problems with other networks. We have a cable modem connected to a Time Capsule, which creates the network, with no extenders or

  • Document Title bar file path

    Hi there I see that when you hover the cursor over the title bar of a PS document the full path is displayed briefly in a tool tip. I was just wondering if there is a way to instead have this display permanently in the title bar itself, in place of j

  • FM for getting org units

    Hi, Is there a FM by which we can get the list of all the lower level depts assigned to a main dept. I mean all the org unit IDs below a specific org unit ID. I am searching for something similar to FM: BBP_OM_STRUC_GET_USER_FROM_ORG, which will give

  • Aggregation level disactivation.

    Hi All. In our solution we use multiProvider and several aggregation levels based on it. When we are updating something in multiProvider all aggregation levels become inactive. It is very boring to activate each aggregation level by hand. Does anybod

  • Custom Scheduling

    I am asking my question prematurely as the business requirement is fluid at the moment. The need here is to schedule reports based on the last business day of the week. If the end of month fall mid-week, then the report should run on that day too. My