How To Resolve Mutating Table Error In Oracle
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 Blog
Fix Oracle mutating mutating trigger in oracle 11g trigger table errors Oracle Database Tips by Burleson Consulting A mutation table is defined as aMutating Trigger In Oracle 10g With Example
table that is changing. But in dealing with triggers, it is a table that has the possibility of changing. What this means to a
Mutating Trigger With Example
trigger is that 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
Oracle Mutating Trigger Pragma Autonomous Transaction
(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 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 oracle statement level trigger 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 commit/rollback affects the entire transaction, it is all or none. Unhandled exceptions in the trigger will cause a rollback of the entire transaction, not just the trigger. If more than one trigger is defined on an event, the order in which they fire is not defined. If the triggers must fire in order, you must create one trigger that executes all the actions in the required order. A trigger can cause other events to execute triggers. A trigger can not change a table that it has read from. This is the mutating table error issue. The fact t
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 policies of this site About Us Learn more about Stack ora-04091 solution Overflow the company Business Learn more about hiring developers or posting ads with us pragma autonomous_transaction in trigger Database Administrators Questions Tags Users Badges Unanswered Ask Question _ Database Administrators Stack Exchange is a question and answer site for database oracle instead of trigger professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can http://www.dba-oracle.com/t_avoiding_mutating_table_error.htm 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. 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 http://dba.stackexchange.com/questions/5432/what-are-the-causes-and-solutions-for-mutating-table-errors 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 this kind of trigger you would expect the query (2) to see the row inserted on (1). This would be in contradiction with both points above since the update is not finished yet (there could be more rows to be inserted). Oracle could return the result consistent with a point in time just before the beginning of the state
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 http://www.geekinterview.com/question_details/38947 SAP 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 http://stackoverflow.com/questions/6915325/oracle-after-update-trigger-solving-ora-04091-mutating-table-error 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 mutating trigger dependent tables, will it get a mutating error? Interview Candidate Dec 1st, 2006 16 52620 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 mutating trigger in if the trigger attempts to 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 finishedhere for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ORACLE After update trigger: solving ORA-04091 mutating table error up vote 2 down vote favorite I am trying to create a trigger: create or replace trigger NAME_OF_TRIGGER after insert or update on table1 REFERENCING OLD AS OLD NEW AS NEW for each row to fill in automatically a couple of non obligatory fields when updating/inserting on a table. This requires me to use a cursor that selects from table2 and also table1 (the subject of the trigger). Is there any way to avoid the mutating table error without using a temporary table for values or an autonomous transaction? sql oracle plsql triggers mutating-table share|improve this question edited Aug 2 '11 at 16:54 APC 87.2k1384184 asked Aug 2 '11 at 16:26 JoséNunoFerreira 150111 add a comment| 1 Answer 1 active oldest votes up vote 7 down vote accepted "Is there any way to avoid the mutating table error without using a temporary table for values or an autonomous transaction?" tl;dr no. The mutating table error is caused by querying the table which owns the trigger, or tables which are involved in a foreign key relationship with the owning table (at least in older versions of the database, not sure whether it still obtains). In a properly designed application this should not be necessary. This is why many people regard mutating tables as an indicator of poor data modelling. For instance, mutation is often associated with insufficient normalisation. To paraphrase Jamie Zawinski: Some people, when confronted with