How to troubleshoot the ora-04091: table of mutation

Hi all

Oracle version: 10g express.

case study: a class has many students, that a student has rewards.

original design:
drop table student;
drop table class;

create table class(
clsid varchar2(9) primary key);

create table student(
stuid varchar2(9) primary key,
clsid varchar2(9) not null references class(clsid) on delete cascade,
reward varchar2(9));
sample data:
insert into class values('cls1');
insert into student values('stu1','cls1','yes');
issues related to the:
1. If I want to
 insert into student values('stu2','cls1','yes'); 
I can put a trigger on student to check if he has that one student in class reward. This trigger must tell me error: I can not leave 'stu2' a 'Yes' on the column of the reward. But he'll lead us Oracle error: ora-04091: table of mutation. He seems to use 'after' or 'instead of' trigger can solve this problem, then how?

2. Another way to ensure that a student in a class reward, is to change the design as:
drop table student;
drop table class;

create table class(
clsid varchar2(9) primary key,
reward_stuid varchar2(9));

create table student(
stuid varchar2(9) primary key,
clsid varchar2(9) not null references class(cid) on delete cascade);
But the question of these two tables has one foreign key to the other, is it good design?

Thank you.

Published by: 991096 on April 11, 2013 04:56

Do not use a trigger for this. This is the logic that you should include in your application as a 'check' pre before even attempting insert, or...
You use an INSERT... SELECT... statement that incorporates the audit as part of it, so the line will be inserted only if the proper test is satisfied.

for example

insert into student (stuid, clsid, reward)
select 'stu2', 'cls1', 'yes'
from   dual left outer join student s2 on (s2.clsid = 'cls1' and s2.reward = 'yes')
where  s2.stuid is null; -- only insert if no other student is found in same class already with reward

and then, your application can control SQL ROWCOUNT % to see if the line was inserted or not.

(Similarly, you can use a MERGE statement or clause EXISTS (NOT) or any method to do so)

Tags: Database

Similar Questions

  • ORA-04091: table is mutation in a scenario

    Hello everyone

    I have a scenario like this:

    There are 2 diagrams USER1 and USER2. There is a table (say STATUS_TABLE) with a similar structure in the two schemas. In a scenario of some USER1 must say USER2 about a flag that needs updates in user2. STATUS_TABLE. For this, an intermediate table (called INTER_TABLE) was created. Now USER1 inserts an entry in the INTER_TABLE table and there is a trigger for insertion on the INTER_TABLE that updates this indicator in USER2. STATUS_TABLE. Once this update is over, record in INTER_TABLE is useless and should be deleted. Now the delete statement in the same trigger on INTER_TABLE laying ORA-04091: table is the mutation. The same thing must hapeen in the other direction as well (for example user1 user2).

    Something like this:
    USER1.STATUS_TABLE          INTER_TABLE          USER2.STATUS_TABLE
                       1 row inserted
               ---------------->
                        trigger on insert------->update a flag here
                      delete that rec from INTER_TABLE     
                           => ORA-04091: table is mutating
    What would be the good approach to perform this feature?

    I hope I explained the scenario correctly :). If you need more details, please let me know

    Thank you
    Amardeep Sidhu

    Amardeep Sidhu wrote:
    In fact, USER1 & USER2 are in different databases and are managed by different vendors.

    You said at first the different schemas. Now, you say too different databases.
    So, need you a database link then, right?

    Amardeep Sidhu wrote:
    And they can not give each other the privilege to insert directly to STATUS_TABLE. So there must be an intermediate table for communication.

    Do you mean that they want to control the code that performs the insert/update in their own table of STATUS?
    In the affirmative. Then let him write a stored procedure to it. And grant execute on the stored procedure to the other provider (vice versa).

    The table mid-range + remains of trigger solution "outlandish."

  • How to handle the ORA-00942: table or view does not exist

    HII All,

    I'm trying to delete a table dynamically independently of its existence in a procedure. Sound fine when the table exists, but when the table does not work I am facing following error
     ORA-00942: table or view does not exist
    I've made use of pragma exception_init and modified my code like below
    Create or replace Procedure sp_FSASA_FEEDUPLOAD_process
              (
               p_test_dir               in     varchar2,
               p_feed_file_name     in     varchar2
              )
    is
              l_exttable_str varchar2(32000) ;
              
              l_log_file constant varchar2(200) := 'logfile_rgh.log';
              
              l_table_doesnt_exist Exception;
              
              pragma exception_init(l_table_doesnt_exist,-00492);
              
              
              
    Begin
              
              Begin
                   execute immediate 'drop table FSASA_FEEDUPLOAD_EXT purge' ;
              Exception
                        when l_table_doesnt_exist then
                             null;
              
              End;
              
              
              
              
              l_exttable_str := 'Create table FSASA_FEEDUPLOAD_EXT ';
              l_exttable_str := l_exttable_str||' ( ';
              l_exttable_str := l_exttable_str||' Category_No                    varchar2(1), ';
              l_exttable_str := l_exttable_str||' Financial_Category          varchar2(300), ';
              l_exttable_str := l_exttable_str||' GFCID                         number, ';
              l_exttable_str := l_exttable_str||' Balance                         number(34,14), ';
              l_exttable_str := l_exttable_str||' Refernce_no                    varchar2(20), ';
              l_exttable_str := l_exttable_str||' Account_no                    varchar2(20), ';
              l_exttable_str := l_exttable_str||' ce_trans_id                    varchar2(20) ';
              l_exttable_str := l_exttable_str||' ) ';
              l_exttable_str := l_exttable_str||' Organization external ';
              l_exttable_str := l_exttable_str||' ( ';
              l_exttable_str := l_exttable_str||' type                    oracle_loader ';
              l_exttable_str := l_exttable_str||' default directory      '||p_test_dir;
              l_exttable_str := l_exttable_str||' Access parameters ';
              l_exttable_str := l_exttable_str||' ( ';
              l_exttable_str := l_exttable_str||'  records delimited by newline ';
              l_exttable_str := l_exttable_str||'BADFILE '||q'[']'||p_test_dir||q'[']'||':'||q'[']'||'feed.bad '||q'[']' ;
              l_exttable_str := l_exttable_str||'LOGFILE '||q'[']'||p_test_dir||q'[']'||':'||q'[']'||':feed.log '||q'[']' ;
              l_exttable_str := l_exttable_str||q'[FIELDS TERMINATED BY X'09']';
              l_exttable_str := l_exttable_str||' missing field values are null ';
              l_exttable_str := l_exttable_str||')location('||q'[']'||p_feed_file_name||q'[']';
              l_exttable_str := l_exttable_str||')' ;
              l_exttable_str := l_exttable_str||' )Reject limit unlimited ';
              
              dbg_print(l_log_file,'l_exttable_str : '||l_exttable_str);
    
              
              execute immediate l_exttable_str;
    
    
    End;
    But I am still unable to get rid of him. Pls help me.

    (1) I need the drop because I need to immediately create the table with the name of different file and different path.

    (2) the last thing I do not do is to check the name of the table in the USER_OBJECTS and then drop.

    (3) suggest that create an external table dynamically as a correct approach or not.

    (4) up to now, we use utl_file for reading stream file but I am much interested to use the concept of EXTERNAL TABLE.

    (5) as the file name and the path is changed, I need to create my external table during execution.

    Please suggest me that I can change my file name and the path when running

    Don't drop and re-create it, just create once as DDL not in code and then change it to point to a new file.

    External table

  • How to troubleshoot the ORA-03114

    Hi all
    I am really surprised why this error is coming in this particular form.
    I have developed two forms
    first of all, I developed a web_util about the shape of the function in this form, I am using this code
    below in when button pressed

    DECLARE
    Rowcol varchar (20);

    cursor mm is
    Select ENAME from SCOTT.emp; - but this line, it appears error ORA-03114

    BEGIN
    I'm looping mm
    When out mm % notfound;
    Rowcol: = i.ENAME;
    end loop;
    END;

    then, after getting this error, I developed another form for testing the error
    I wrote this code in when button pressed
    DECLARE
    CURSOR MM IS
    SELECT ENAME FROM EMP;

    BEGIN
    GO_BLOCK ('EMPGRID_BLK');
    CLEAR_BLOCK (NO_VALIDATE);
    LAST_RECORD();
    FOR REC IN MM LOOP
    WHEN OUT MM % NOTFOUND;
    : EMPGRID_BLK. TEXT_ENAME: = REC. ENAME;
    CREATE_RECORD();
    END LOOP;
    FIRST_RECORD();
    END;
    It works very well.

    Please help me why this error comes from the first form in fact where is the problem
    my version of forms is: = Forms [32 bit] Version 10.1.2.0.2 (Production)
    database version: = database Oracle 10 g Enterprise Edition Release 10.2.0.3.0
    operating system is windows xp sp2

    any help is deeply appreciated please give solution clean/pine point.

    Please answer...

    Hello

    where you get the record?

    try something like that.
    connect to the database with the user scott.

    declare
    
    rowcol varchar(20);
    
    cursor mm is select ENAME from emp; 
    
    BEGIN
    
    for i in mm loop
    exit when mm%notfound;
    rowcol := i.ename;
    end loop;
    
    END;
    

    Sarah

  • Changing table - SQL error: ORA-04091: table XYZ is changing, function of triggering/can not see

    Hi all

    I am a newbie to Oracle and I am faced with the above error. Please see the below code snippets. Can someone please tell what I am doing wrong? Thank you in advance.

    Thank you

    CREATE TABLE ABC

    (

    ID VARCHAR2 ENABLE NUMBER NOT NULL,

    FIELD1 ACTIVATE THE NUMBER NOT NULL,

    FIELD2 ACTIVATE THE VARCHAR2 (8 BYTE) NOT NULL,

    CONSTRAINT JOB_PK PRIMARY KEY (ID)

    )

    ;

    CREATE TABLE XYZ

    (

    ACTIVATE THE NUMBER 4 R_ID NOT NULL,.

    ID VARCHAR2 ENABLE NUMBER NOT NULL,

    Column1 NUMBER (2.0) default 0.00,.

    Column2 NUMBER (2.0) default 0.00,.

    COLUMN3 NUMBER (2.0).

    NUMBER (2.0) TOTAL 0.00 default.

    CONSTRAINT TRIP_PAYMENT_PK PRIMARY KEY (ID)

    )

    ;

    create or replace trigger trigger1

    After Insert on XYZ

    for each line

    Declare

    number of newTotal;

    Start

    newTOTAL: =: new. Column1 +: new. Column2 +: new. COLUMN3;

    setting a day of XYZ together Total = newTotal;

    end;

    Insert into ABC (1, 45, ' Demo');

    insertion in XYZ (1, 1, 12.50, 10.20 33,50, ");

    Error report:

    SQL error: ORA-04091: table XYZ is changing, function of triggering/can not see

    Try one before line

    create or replace trigger trigger1

    before inserting on XYZ

    for each line

    Start
    : new. TOTAL: =: new. Column1 +: new. Column2 +: new. COLUMN3;
    end;

  • How to save the data in table 1 d to Excel in continuous

    Mr President.

    How to save the data in table 1 d to Excel at all times, so that all the data of the first scan must be placed first thought and all the data from the second analysis must be placed on the second Board and continue on the street...

    Sy@m...

    Hi Sy@m

    Here is a vi that might give you a few ideas to try:

  • How to troubleshoot the plugin does not not in Acrobat

    Hi all

    I am just starting to develop my Plugin and I'm unable to troubleshooting / debugging.

    First of all, a bit of history:

    I start with a simple example, based on the example of BasicPlugIn that adds a menu item that displays a form of language c# .NET. I have the .NET extracted via a C++ wrapper shape.  I'll call the wrapper of the plug. At this point, the MyPlugInCommand method has a single line:

    CFW CoyoMenuFormsWrapper;

    This line is simply instantiated the exported class.

    If I DELETE this line and debug, everything is great. I touched my breakpoints and the menu item is displayed in Acrobat format.

    If I LEAVE this line and debug then nothing. No point of debugging, no menu item.

    I suspect this is a. Problem loading the DLL and I conducted depends.exe the and it showed nothing unusual. The exported dll that has the wrapper (Adobe2Net) is present and reported in detail.

    Acrobat records all errors that might give me a clue? I see nothing in the event logs or ProgramData. Any other suggestions on how to troubleshoot the loading has failed?

    Thank you

    Mark

    .

    Just followed this issue closely.

    I could get my plugin to work if the DLL in the folder plug_ins, but which was not possible for me. I opted to go down the road of COM Interop and it works very well.

    Thanks for the help.

    Mark

  • How to find the user Apex table

    Hello

    Please let me know, how to find the user apex table. I need validate the unique user based on the same, for which I use below function.

    DECLARE
    VAL A BOOLEAN;
    BEGIN
    VAL: = APEX_UTIL.IS_USERNAME_UNIQUE (p_username =
    (: P6_USERNAME);
    END;

    However, in this case, he always comes back "FALSE," saying new user exists.

    Kindly help me in fixing this problem.

    There is a view called apex_workspace_apex_users.

    Details under Home > utilities > Application Express views

    André

  • How to capture the ORA-6550

    I want to find the ORA-06550 errors

    SQL> alter session set events 'sql_trace';
    
    Session altered.
    
    SQL> select 'foo' from dual;
    
    'FO
    ---
    foo
    
    SQL> exec foo
    BEGIN foo; END;
    
          *
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'FOO' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    
    
    SQL> quit
    
    


    If I look in my trace file, I don't find any ORA-6550

    Trace file /u01/log/oracle/diag/rdbms/db01/DB01/trace/DB01_ora_42860586.trc
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_3
    System name:    AIX
    Node name:      srv01
    Release:        1
    Version:        7
    Machine:        00F626FA4C00
    Instance name: DB01
    Redo thread mounted by this instance: 1
    Oracle process number: 38
    Unix process pid: 42860586, image: [email protected] (TNS V1-V3)
    
    
    *** 2015-09-17 13:59:49.109
    *** SESSION ID:(358.241) 2015-09-17 13:59:49.109
    *** CLIENT ID:() 2015-09-17 13:59:49.109
    *** SERVICE NAME:(SYS$USERS) 2015-09-17 13:59:49.109
    *** MODULE NAME:([email protected] (TNS V1-V3)) 2015-09-17 13:59:49.109
    *** ACTION NAME:() 2015-09-17 13:59:49.109
    
    CLOSE #4573396320:c=6,e=10,dep=0,type=1,tim=49416422688162
    =====================
    PARSING IN CURSOR #4573391040 len=22 dep=0 uid=0 oct=3 lid=0 tim=49416422690646 hv=3859763380 ad='70000005ae19830' sqlid='cvysbzgm0yn5n'
    select 'foo' from dual
    END OF STMT
    PARSE #4573391040:c=790,e=1312,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=1,plh=1546270724,tim=49416422690645
    EXEC #4573391040:c=18,e=31,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,plh=1546270724,tim=49416422690748
    FETCH #4573391040:c=8,e=13,p=0,cr=0,cu=0,mis=0,r=1,dep=0,og=1,plh=1546270724,tim=49416422690808
    STAT #4573391040 id=1 cnt=1 pid=0 pos=1 obj=0 op='FAST DUAL  (cr=0 pr=0 pw=0 time=4 us cost=2 size=0 card=1)'
    FETCH #4573391040:c=0,e=1,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=0,plh=1546270724,tim=49416422691085
    
    *** 2015-09-17 13:59:57.118
    CLOSE #4573391040:c=7,e=12,dep=0,type=0,tim=49416430697630
    =====================
    PARSING IN CURSOR #4573389592 len=202 dep=1 uid=0 oct=3 lid=0 tim=49416430698685 hv=3819099649 ad='700000066ccf5b8' sqlid='3nkd3g3ju5ph1'
    select obj#,type#,ctime,mtime,stime, status, dataobj#, flags, oid$, spare1, spare2 from obj$ where owner#=:1 and name=:2 and namespace=:3 and remoteowner is null and linkname is null and subname is null
    END OF STMT
    PARSE #4573389592:c=59,e=95,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=853875749,tim=49416430698684
    EXEC #4573389592:c=32,e=52,p=0,cr=0,cu=0,mis=0,r=0,dep=1,og=4,plh=853875749,tim=49416430698837
    FETCH #4573389592:c=18,e=31,p=0,cr=2,cu=0,mis=0,r=0,dep=1,og=4,plh=853875749,tim=49416430698888
    STAT #4573389592 id=1 cnt=0 pid=0 pos=1 obj=18 op='TABLE ACCESS BY INDEX ROWID OBJ$ (cr=2 pr=0 pw=0 time=37 us cost=3 size=80 card=1)'
    STAT #4573389592 id=2 cnt=0 pid=1 pos=1 obj=37 op='INDEX RANGE SCAN I_OBJ2 (cr=2 pr=0 pw=0 time=34 us cost=2 size=0 card=1)'
    CLOSE #4573389592:c=1,e=1,dep=1,type=3,tim=49416430698970
    
    *** 2015-09-17 14:00:00.974
    XCTEND rlbk=0, rd_only=1, tim=49416434554077
    CLOSE #4573391040:c=1,e=6,dep=0,type=0,tim=49416434554235
    
     

    How is it possible to capture the ORA-06550 and underlying instructions exec?

    Thank you

    Laurent

    Laurent,

    You can draw more precisely by using:

    ALTER session set events "6550 trace name errorstack level 1";

    and,

    ALTER session set events ' trace name errorstack off 6550;

  • How to change the height in table of the field of Bitmaps

    Dear developers BB,

    I work with a table of the field (3 x 3) whose I am filled with bitmap images.

    I loaded all 9 images successfully, but I don't know how to resize the height of the lines if the pictures would be good.

    Any help would be greatly appreciated.

    Code snippet:

    In the main routine:

    Field [] [] tableContent = new field [3] [3];

    tableContent [0] [0] = new BitmapField (TopLeft);

    ...

    tableContent [2] [2] = new BitmapField (BotRight);

    int [] width = {40, 40, 40};

    paddings of int [] = {20,20,20};

    Screen.Add (new TableListField (tableContent, widths, paddings));

    pushScreen (screen);

    outside the main routine...

    private final static Bitmap TopLeft = Bitmap.getBitmapResource ("topleft.jpg");

    ...

    private final static Bitmap BotRight = Bitmap.getBitmapResource ("botright.jpg");

    class TableListField extends ListField

    public TableListField ([] [], int [] columnWidths field content,
    int [] horizontalPaddings)
    {
    numRows = contents.length int;

    Create a line for each line.
    _rows = new TableRowManager [numRows];
    for (int curRow = 0;  curRow< numrows; ="" currow++)="">
    _rows [curRow] = new TableRowManager (happy [curRow]);
    }

    _columnWidths = columnWidths;
    _horizontalPaddings = horizontalPaddings;
    setSize (numRows);
    setCallback (RENDERER);
    }

    I imagine that your RENDERING engine takes three images for each line and displays those all the row using a drawBitmap (...) for each?

    In any case, the height of the row in the ListField is controlled by the ListField.setRowHeight () method.  You probably want to replace this:

    Screen.Add (new TableListField (tableContent, widths, paddings));

    with

    TabList TableListField = new TableListField (tableContent, widths, paddings);

    tabList.setRowHeight (TopLeft.getHeight () + 1);

    Screen.Add (tabList);

    I hope this helps.

  • How to operate the user defined table ddl transformations?

    How can I run (Oracle Data Modeller 4.1.0.873) my transformations of the user-defined table ddl (for the creation or - map source files). (In tools-> rules of design and Transformations-> Table DDL transform his only Test and debugging for an entity)

    Is it possible to have a new button in the toolbar to start my generations DDL?

    Hello

    There is a brief description in the file sqldeveloperdatamodelerscripting.docx located in the directory datamodeler\datamodeler\xmlmetadata\doc of your DM 4.1 instalation.

    Somehow you can read also here Oracle SQL Developer Data Modeler 4.1 user - defined DDL generation using transformation scripts

    You can use the script for the purposes of testing only, otherwise the output of this script will be included in the DDL if script 'Active' selected value and ago marked to be included in this generation of tables

    Philippe

  • How to call the procedure type table

    Hi I have the below requirement

    Created in the sub table type

    CREATE or REPLACE the TYPE char_type IS the TABLE OF VARCHAR2 (4000);

    create or replace procedure test_proc_type (p_type char_type) is

    Start

    I'm looping 1.p_type.count

    dbms_output.put_line (p_type (i));

    end loop;

    end;

    How to call the procedure with parameter as a type!

    SQL> create or replace type  char_type as table of varchar2(4000)
      2  /
    
    Type created.
    
    SQL> create or replace procedure test_proc_type (p_type char_type)
      2  is
      3  begin
      4    for i in 1..p_type.count loop
      5      dbms_output.put_line (p_type(i) ) ;
      6    end loop;
      7  end;
      8  /
    
    Procedure created.
    
    SQL> set serveroutput on
    SQL>
    SQL> exec test_proc_type(char_type('A','B','C','D','E'))
    A
    B
    C
    D
    E
    
    PL/SQL procedure successfully completed.
    
    SQL>
    
  • Troubleshooting the lack of table of contents level

    I'm under InDesign CS6. For some reason any my level 1 paragraph styles are not appearing in the table of contents (which looks pretty otherwise). I use Master Pages... one is the first Page of chapter. He uses the paragraph style "chapter titled new L1. I synced the book. I made sure whenever I use this Master Page that point to the same paragraph style. Each chapter is a new document. What Miss me?

    Here is the master page

    fpoc.png

    Here it is in use

    intro.png

    Here is how to generate the table of contents.

    toc2.png

    Of course, you must override on the page of the document (and not the master page) in order for InDesign to 'see' the content in the frame as belonging to this page (and so put it in the table of contents). For example, if your position is on page 5, you must override the image on page 5 with command + shift (Mac) or Ctrl + Shift (Windows) and clicking on the image. The dotted frame will change to a solid frame on this page. Then go to your table of contents page, select the image containing the table of contents and in the menu layout and choose Update Table of contents. You need to replace the image on each page of the document where it contains the content that you want to appear in the table of contents.

  • How to use the T distribution table in sql statements?

    Hi all

    I'm in the need to use the T distribution table in sql... I don't know how to use...

    Is there a function to use the values of table in sql statements?

    Can someone please help me in this?

    How about this http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions157.htm#i1279931?

    Concerning

    Etbin

  • SG-500-28 P how to display the mac address table?

    The command standare Cisco IOS is see table of mac addresses. This command is not available on this switch.

    V1.3.0.62 FW

    Thank you.

    See the mac address table

Maybe you are looking for

  • Satellite A210-199 - (PSAFGE) - error in BIOS

    Good day. Face the problem of laptop model Toshiba A210 - 199 (PSAFGE)When the computer laptop 2 times and hits of mail to oshybku System Configuration data updates andAlong System Configuration data read error That please?Thanks in advance I'm from

  • Satellite M30-106: USB Ports not working not

    Hello. I have a problem with my Satellite M30-106. One day, the system froze (Windows XP with SP2) during the passage of the machine off. I was forced to keep the button "power" for a while in order to close the system. However, since all 3 USB ports

  • Configuration of the DMZ for MS access

    I set up a DMZ for a Web server. I'll probably put an RODC in there later, but for now I want to open ports to the domain controller. I'm a bit new to DMZ and I'm a bit confused. I put in place services for different ports and then configure the rule

  • G motorcycle battery problem?

    I just brought bike g 16 GB of Republic wireless. The problem is that or (I think it's a problem I don't know) the battery lasts for only 1 night. Is - even for others, or is this just me? Thank you!!

  • Cartridges found printing or misssing

    No idea how to do to pass this message on my screen of the printer. The cartridges are properly housed certaainly, but the thing will not accept the fact. I am able to pass this message please? Pete