How To Resolve Mutating Table Error
Contents |
SQL TuningSecurityOracle UNIXOracle LinuxMonitoringRemote supportRemote plansRemote servicesApplication Server ApplicationsOracle FormsOracle PortalApp UpgradesSQL ServerOracle ConceptsSoftware SupportRemote Support Development Implementation Consulting StaffConsulting PricesHelp Wanted! Oracle PostersOracle Books Oracle Scripts Ion Excel-DB Don Burleson mutating table error in oracle with example Blog
Mutating Trigger In Oracle 11g
Fix Oracle mutating trigger table errors Oracle Database Tips by Burleson Consulting A mutation table is defined as mutating trigger in oracle 10g with example a table that is changing. But in dealing with triggers, it is a table that has the possibility of changing. What this means to a trigger is that if the trigger reads oracle mutating trigger pragma autonomous transaction a table, it can not change the table that it read from. This does not impact the exclusive use of :OLD and :NEW. It says that if the trigger reads the table (such as using a SELECT query), that changes (even using :NEW) will fail. This can also happen when a trigger on a parent table causes an insert on a child table
Mutating Trigger With Example
referencing a foreign key. Mutating Tables Each new release of the Oracle database reduces the impact of the mutating table error on triggers and they are much less of a problem with Oracle9i and above. If a trigger does result in a mutating table error, the only real option is to rewrite the trigger as a statement-level trigger. Mutating table errors only impact row level triggers. But to use a statement level trigger, some data may need to be preserved from each row, to be used by the statement level trigger. This data can be stored in a PL/SQL collection or in a temporary table. A simple row level trigger that causes a mutating table error can result in a very complicated statement level trigger to achieve the needed result. Here are some important items to remember about triggers. On insert triggers have no :OLD values. On delete triggers have no :NEW values. Triggers do not commit transactions. If a transaction is rolled back, the data changed by the trigger is also rolled back. Commits, rollbacks and save points are not allowed in the trigger body. A
log in tour help Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and oracle statement level trigger policies of this site About Us Learn more about Stack Overflow the ora-04091 solution company Business Learn more about hiring developers or posting ads with us Database Administrators Questions Tags Users Badges Unanswered
Pragma Autonomous_transaction In Trigger
Ask Question _ Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join http://www.dba-oracle.com/t_avoiding_mutating_table_error.htm them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top What are the causes and solutions for mutating table errors? up vote 7 down vote favorite 1 I understand mutating table errors are caused by a design flaw or problematic query. http://dba.stackexchange.com/questions/5432/what-are-the-causes-and-solutions-for-mutating-table-errors An old query was recently put into production which throws a mutating table error. Our DBA solved the problem but we do not know how. What exactly causes mutating table errors and how would our DBA have fixed the problem? sql oracle trigger plsql share|improve this question edited Jun 25 '15 at 17:56 Mahi_0707 1033 asked Sep 6 '11 at 8:46 parmanand 112238 add a comment| 3 Answers 3 active oldest votes up vote 13 down vote accepted The most likely cause of a mutating table error is the misuse of triggers. Here is a typical example: you insert a row in table A a trigger on table A (for each row) executes a query on table A, for example to compute a summary column Oracle throws an ORA-04091: table A is mutating, trigger/function may not see it This is an expected and normal behaviour, Oracle wants to protect you from yourself since Oracle guarantees: (i) that each statement is atomic (i.e will either fail or succeed completely) (ii) that each statement sees a consistent view of the data Most likely when you write th
Social Links Printer Friendly About Search 8i | 9i | 10g | 11g | 12c | 13c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux Home » Articles » 9i » Here Mutating https://oracle-base.com/articles/9i/mutating-table-exceptions Table Exceptions Mutating table exceptions occur when we try to reference the triggering table in http://searchoracle.techtarget.com/tip/How-to-avoid-mutating-table-errors a query from within row-level trigger code. In this article I'll present examples of how a mutating table exception might occur and simple methods to get round it. Test Schema Mutating Table Demonstration Solution 1 (Collection in Package Variable) Solution 2 (Global Temporary Table) Test Schema The following schema objects are necessary to run the code in this mutating trigger article. CREATE TABLE tab1 ( id NUMBER(10) NOT NULL, description VARCHAR2(50) NOT NULL ); ALTER TABLE tab1 ADD ( CONSTRAINT tab1_pk PRIMARY KEY (id) ); CREATE SEQUENCE tab1_seq; CREATE TABLE tab1_audit ( id NUMBER(10) NOT NULL, action VARCHAR2(10) NOT NULL, tab1_id NUMBER(10), record_count NUMBER(10), created_time TIMESTAMP ); ALTER TABLE tab1_audit ADD ( CONSTRAINT tab1_audit_pk PRIMARY KEY (id) ); ALTER TABLE tab1_audit ADD ( CONSTRAINT tab1_audit_tab1_fk FOREIGN KEY (tab1_id) REFERENCES tab1(id) ); CREATE mutating table error SEQUENCE tab1_audit_seq; Mutating Table Demonstration Let's assume we need to audit the actions on the parent table and for some reason, this involves querying the triggering table. We can demonstrate this with the following package and trigger. We place all our trigger code into a package as follows. CREATE OR REPLACE PACKAGE trigger_api AS PROCEDURE tab1_row_change (p_id IN tab1.id%TYPE, p_action IN VARCHAR2); END trigger_api; / SHOW ERRORS CREATE OR REPLACE PACKAGE BODY trigger_api AS PROCEDURE tab1_row_change (p_id IN tab1.id%TYPE, p_action IN VARCHAR2) IS l_count NUMBER(10) := 0; BEGIN SELECT COUNT(*) INTO l_count FROM tab1; INSERT INTO tab1_audit (id, action, tab1_id, record_count, created_time) VALUES (tab1_audit_seq.NEXTVAL, p_action, p_id, l_count, SYSTIMESTAMP); END tab1_row_change; END trigger_api; / SHOW ERRORS Next we create the row-level trigger itself to catch any changes to the table. CREATE OR REPLACE TRIGGER tab1_ariu_trg AFTER INSERT OR UPDATE ON tab1 FOR EACH ROW BEGIN IF inserting THEN trigger_api.tab1_row_change(p_id => :new.id, p_action => 'INSERT'); ELSE trigger_api.tab1_row_change(p_id => :new.id, p_action => 'UPDATE'); END IF; END; / SHOW ERRORS If we try to insert into the TAB1 table we might expect the insert to complete and the audit record to be created but as you can see below this is not the case. SQL> INSERT INTO tab1 (id, description) VALUES (tab1_seq.NEXTVAL, 'ONE'); INSERT INTO tab1 (id, description) VALUES (tab1
Topic Error messages Database Admin View All Cloud infrastructure Availability Backup and recovery Database design Export, import and migration Installation, upgrades and patches Oracle performance problems and tuning Oracle security Oracle DBA tools MySQL database Real Application Clusters (RAC) Applications View All Enterprise and business performance management Implementing and upgrading Oracle apps E-Business Suite Fusion applications Hyperion JD Edwards (JDE) PeopleSoft Siebel and Oracle CRM Data Mgmt View All BI (business intelligence) Data quality Data warehousing Metadata Database Admin View All Cloud infrastructure Availability Backup and recovery Database design Export, import and migration Installation, upgrades and patches Oracle performance problems and tuning Oracle security Oracle DBA tools Error messages MySQL database Real Application Clusters (RAC) Development View All BPEL in Oracle Open Source SQL Java / J2EE Stored procedures XML PL/SQL Fusion View All Oracle and BEA Application Server Data and application integration SOA (service-oriented architecture) Infrastructure View All Cloud computing infrastructure Exadata and Exalogic Grid computing Oracle on Linux Operating system Oracle hardware decisions Virtual machine Oracle management View All certification Oracle acquisitions Business process management Market analysis DBA jobs training and certification Small businesses Regulatory compliance Outsourcing Oracle on demand and SaaS Oracle strategy and product roadmap Oracle support services Oracle vs. SAP Oracle Web 2.0 Sun-Oracle infrastructure View All Oracle cloud computing Oracle OS Oracle virtualization Topics Archive View All Oracle DBA jobs Oracle Resources Training and certification Tutorials, tips and FAQs Please select a category Applications Data Mgmt Database Admin Development Fusion Infrastructure Oracle management Sun-Oracle infrastructure Section Manage News Get Started Evaluate Manage Problem Solve Sponsored Communities How to avoid 'mutating table' errors byPravesh Gupta A "mutating table" error can be avoided by writing a procedure/function that declares the pragma autonomous_transaction. In this Article Share this item with your network: Related Content Trigger causing table to mutate – SearchOracle PL/SQL program for complex 8i output – SearchOracle Performing a NOT IN without a subquery – SearchOracle Sponsored News Hyper-Convergence Delivers Better Mission-Critical Performance –SimpliVity Top 5 Questions On Desktop Virtualization and Converged Solutions &ndash