ORA-04091: table JAVA2S.DETAIL_TABLE is mutating, trigger/function may not see it : Drop Table « Table « Oracle PL/SQL Tutorial

Oracle PL/SQL Tutorial
1. Introduction
2. Query Select
3. Set
4. Insert Update Delete
5. Sequences
6. Table
7. Table Joins
8. View
9. Index
10. SQL Data Types
11. Character String Functions
12. Aggregate Functions
13. Date Timestamp Functions
14. Numerical Math Functions
15. Conversion Functions
16. Analytical Functions
17. Miscellaneous Functions
18. Regular Expressions Functions
19. Statistical Functions
20. Linear Regression Functions
21. PL SQL Data Types
22. PL SQL Statements
23. PL SQL Operators
24. PL SQL Programming
25. Cursor
26. Collections
27. Function Procedure Packages
28. Trigger
29. SQL PLUS Session Environment
30. System Tables Data Dictionary
31. System Packages
32. Object Oriented
33. XML
34. Large Objects
35. Transaction
36. User Privilege
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Oracle PL/SQL Tutorial » Table » Drop Table 
6. 8. 3. ORA-04091: table JAVA2S.DETAIL_TABLE is mutating, trigger/function may not see it
SQL>
SQL> CREATE TABLE master_table
  2  (master_id NUMBER NOT NULL PRIMARY KEY);

Table created.

SQL>
SQL> CREATE TABLE detail_table
  2  (detail_id NUMBER NOT NULL,
  3   master_id NUMBER NOT NULL,
  4     CONSTRAINT detail_to_emp
  5     FOREIGN KEY (master_id)
  6     REFERENCES master_table (master_id)
  7     ON DELETE CASCADE);

Table created.

SQL>
SQL> CREATE OR REPLACE TRIGGER after_delete_master
  2  AFTER DELETE ON master_table
  3  FOR EACH ROW
  4  DECLARE
  5    CURSOR curs_count_detail IS
  6    SELECT COUNT(*)
  7      FROM detail_table;
  8    v_detail_count NUMBER;
  9  BEGIN
 10    OPEN curs_count_detail;
 11    FETCH curs_count_detail INTO v_detail_count;
 12    CLOSE curs_count_detail;
 13  END;
 14  /

Trigger created.

SQL>
SQL> BEGIN
  2    FOR master_counter IN 1..10 LOOP
  3      INSERT INTO master_table
  4      VALUES(master_counter);
  5      FOR detail_counter IN 1..2 LOOP
  6        INSERT INTO detail_table
  7        VALUES(detail_counter,
  8               master_counter);
  9      END LOOP;
 10    END LOOP;
 11  END;
 12  /

PL/SQL procedure successfully completed.

SQL>
SQL> SELECT FROM master_table;

 MASTER_ID
----------
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10

10 rows selected.

SQL>
SQL> SELECT FROM detail_table;

 DETAIL_ID  MASTER_ID
---------- ----------
         1          1
         2          1
         1          2
         2          2
         1          3
         2          3
         1          4
         2          4
         1          5
         2          5
         1          6

 DETAIL_ID  MASTER_ID
---------- ----------
         2          6
         1          7
         2          7
         1          8
         2          8
         1          9
         2          9
         1         10
         2         10

20 rows selected.

SQL>
SQL> DELETE master_table;
DELETE master_table
       *
ERROR at line 1:
ORA-04091: table JAVA2S.DETAIL_TABLE is mutating, trigger/function may not see
it
ORA-06512: at "JAVA2S.AFTER_DELETE_MASTER", line 3
ORA-06512: at "JAVA2S.AFTER_DELETE_MASTER", line 7
ORA-04088: error during execution of trigger 'JAVA2S.AFTER_DELETE_MASTER'


SQL>
SQL> SELECT FROM master_table;

 MASTER_ID
----------
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10

10 rows selected.

SQL>
SQL> SELECT FROM detail_table;

 DETAIL_ID  MASTER_ID
---------- ----------
         1          1
         2          1
         1          2
         2          2
         1          3
         2          3
         1          4
         2          4
         1          5
         2          5
         1          6

 DETAIL_ID  MASTER_ID
---------- ----------
         2          6
         1          7
         2          7
         1          8
         2          8
         1          9
         2          9
         1         10
         2         10

20 rows selected.

SQL>
SQL> DROP TABLE detail_table;

Table dropped.

SQL> DROP TABLE master_table;

Table dropped.

SQL>
SQL>
SQL>
6. 8. Drop Table
6. 8. 1. Dropping a Table
6. 8. 2. DROP TABLE with CASCADE CONSTRAINTS
6. 8. 3. ORA-04091: table JAVA2S.DETAIL_TABLE is mutating, trigger/function may not see it
6. 8. 4. Drop only if table exists.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.