Mutation 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 mutating trigger in oracle 11g Don Burleson Blog
Mutating Trigger In Oracle 10g With Example
Fix Oracle mutating trigger table errors Oracle Database Tips by Burleson Consulting A mutation table is oracle mutating trigger pragma autonomous transaction defined as 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 mutating trigger with example if the trigger reads 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
Mutating Table Error In Oracle 11g With Example
insert on a child table 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
Social Links Printer Friendly About Search 8i | 9i | 10g | 11g | 12c | 13c | Misc | PL/SQL | SQL | RAC | WebLogic | Linux Home » Articles » 9i » Here statement level trigger in oracle Mutating Table Exceptions Mutating table exceptions occur when we try to reference the triggering ora-04091 solution table in a query from within row-level trigger code. In this article I'll present examples of how a mutating table exception
Pragma Autonomous_transaction In Trigger
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 http://www.dba-oracle.com/t_avoiding_mutating_table_error.htm the code in this 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 https://oracle-base.com/articles/9i/mutating-table-exceptions (tab1_id) REFERENCES tab1(id) ); CREATE 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, desc
Management Accounting Operating System Operating System Android iOS Microsoft Coding Programming J2EE Languages Database Database Data Warehousing Oracle Applications Applications Clarify CRM Oracle Apps Peoplesoft Siebel Software Testing Testing Testing Tools Miscelleanous Helpdesk Mainframe Networking SAP http://www.geekinterview.com/question_details/38947 R/3 Web Interview Coaching Career Counseling Job Interview Interview eBooks Accounting eBook C eBook Citrix eBook Job Interview eBook Career Advice Career Change Jobs Help Projects Requests Resume Help Training Advice Engineering Chemical Engineering Civil Engineering Electrical Engineering Electronics Engineering Micro Processor Mechanical Engineering By Company Ask Question Home Interview QuestionsOraclePL/SQL What is mutating trigger? How do you resolve it?If a trigger body is trying to update dependent tables, will mutating trigger it get a mutating error? Interview Candidate Dec 1st, 2006 16 52841 PL/SQL Answer First Prev Next Last Showing Answers 1 - 16 of 16 Answers PAWAN AHUJA Dec 3rd, 2006 Mutating trigger is trigger that is currently being modified by DML opertion.we can resolve it by applying statement lelel trigger.RegardsPawan Ahuja
Was this answer useful?Yes 1 Reply manikandan Dec 8th, 2006 if the trigger attempts to trigger in oracle select or modify the table while the trigger has not completed (ie. table is in transition). then mutating trigger error occurs.because the table is in middle of a transaction so it causes the trigger to mutate.you can change the trigger to statement level and apply the logic there. Was this answer useful?Yes Reply vikramssheth ProfileAnswers by vikramssheth Jan 30th, 2007 We can override this problem using temporary Table Concept. Was this answer useful?Yes Reply sripri ProfileAnswers by sripriQuestions by sripri May 8th, 2007 Mutating trigger has similar concept to that of deadlock. When a table is in the half way of executing a transaction and is the owner of a trigger and if the same table is accessed by the trigger somewhere else in the same time then at that instance mutating trigger occurs. Was this answer useful?Yes Reply Robert ProfileAnswers by RobertQuestions by Robert May 8th, 2007 To avoid Mutating trigger there are many ways. One of the best approach is to make use of the after trigger which clearly takes care of concurrency problems associated with mutating triggers .When after trigger is used only after the process of current updating is finished the next process gets processed. Was this answer