Oracle Sql Error Ora-04091
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 ora-04091 table is mutating trigger/function may not see it ora-06512 Books Oracle Scripts Ion Excel-DB Don Burleson Blog ora-04091 solution
Fix Oracle mutating trigger table errors Oracle mutating trigger in oracle 10g with example Database Tips by Burleson Consulting A mutation table is defined as a table that is changing. But in dealing with triggers, it is a table that has the mutating trigger in oracle 11g possibility of changing. What this means to a 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 (such as using a SELECT query), that changesOracle Statement Level Trigger
(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 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
- 8:40 pm UTC Category: SQL*Plus � Version: 8.1.7 Whilst you are here, check out some content from the AskTom team: TwitterQuiz results: What could be safely deleted from this code? Latest Followup You Asked hello, i've got a table MRC and a trigger on
Oracle Instead Of Trigger
it (AFTER INSERT) thus, after an insert in the table MRC, this trigger has to determine oracle mutating trigger pragma autonomous transaction if a new line must be inserted into an other table PLAN : for that, it does compare the :new values with the ora-04091 after insert trigger MOST RECENT enregistrement of MRC but i got a mutating table error i understand the problem but how can i get over ?? thanks Arnaud and we said... My personal opinion -- when I hit a mutating table error, http://www.dba-oracle.com/t_avoiding_mutating_table_error.htm I've got a serious fatal flaw in my logic. Have you considered the multi-user implications in your logic? Two people inserting at the same time (about the same time). What happens then??? Neither will see eachothers work, neither will block -- both will think "ah hah, I am first"... anyway, you can do too much work in triggers, this may well be that time -- there is nothing wrong with doing things in a more straightforward fashion (eg: using https://asktom.oracle.com/pls/apex/f?p=100:11:0%3A%3A%3A%3AP11_QUESTION_ID:9579487119866 a stored procedure to implement your transaction) but if you persist, you can use the technique: http://asktom.oracle.com/~tkyte/Mutate/index.html to avoid the mutating table constraint -- but I would avoid the situation that gets me there in the first place. The logic is a whole lot more understandable that way (and maintainable and testable and everything) Reviews Write a Review Ora-4091 May 05, 2003 - 5:45 pm UTC Reviewer: A reader We create trigger in the test server (8i) its working without error, and when we created at life (8) we get the following error: ORA-04091: table XXXX is mutating, trigger/function may not see it. Followup May 05, 2003 - 8:31 pm UTC they relaxed some of the constraining rules between 8.0 and 8.1 -- things are in general upwards (develop in 8.0 and goto 8.1) compatible but not backwards. Why I can't get the 4091 error when insert? January 05, 2004 - 3:39 am UTC Reviewer: Li ys from CHINA I only want to prove the mutating table by this triggers: CREATE TABLE r_Module ( Bureauno NUMBER(3), Moduleno NUMBER(3), primary key ( Bureauno, Moduleno ) ); CREATE OR REPLACE TRIGGER LimitTest BEFORE INSERT OR UPDATE ON r_Module FOR EACH ROW DECLARE v_MaxModuleNum CONSTANT NUMBER := 5; v_CurModuleNum NUMBER; BEGIN SELECT COUNT(*) INTO v_CurModuleNum FROM r_Module WHERE Bureauno = :new.Bureauno; IF v_CurModuleNum + 1 > v_MaxModuleNum THEN RAISE_APPLICATION_ERROR(-20000,'Too many Module in the Bureauno:'||:new.Bureauno);
here for a quick overview of the site Help Center Detailed answers to http://stackoverflow.com/questions/32716242/ora-04091-table-is-mutating-trigger-function-may-not-see-it-error-during-execu any questions you might have Meta Discuss the workings and http://stackoverflow.com/questions/6915325/oracle-after-update-trigger-solving-ora-04091-mutating-table-error 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 mutating trigger Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ORA-04091: table is mutating, trigger/function may not see it error during execution of oracle trigger up vote 0 down vote favorite 1 I have below trigger in mutating trigger in which for FIELD_NAME field i want to insert value into FIELD_TRACKING table as 'Deactivation time of KPI in case of Downtime(Select KPI_FREQ_TIME_UNIT FROM KPI_DEFINITION)'. The bracket part in this string value comes from KPI_FREQ_TIME_UNIT field of KPI_DEFINITION table. So below is the trigger i have wrritten for this. The trigger compile without any error. But when i try to change the DNTM_REAC_AFTER_HRS field from the KPI_DEFINITION table then i am getting error ORA-04091: table RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION is mutating, trigger/function may not see it ORA-04088: error during execution of trigger 'RATOR_MONITORING_CONFIGURATION.TRG_TRK_KPI_DEFINITION'. create or replace TRIGGER RATOR_MONITORING_CONFIGURATION."TRG_TRK_KPI_DEFINITION" AFTER UPDATE ON RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION FOR EACH ROW IF NOT :old.DNTM_REAC_AFTER_HRS=:new.DNTM_REAC_AFTER_HRS THEN INSERT INTO RATOR_MONITORING_CONFIGURATION.FIELD_TRACKING (FIELD_TRACKING_ID,TABLE_NAME,TABLE_ID, FIELD_NAME,FIELD_OLD_VALUE,FIELD_NEW_VALUE,USER_ID, TIMESTAMP, FIELD_TRACKING_COMMENTS) VALUES (FIELD_TRACKING_SEQ.NEXTVAL,'KPI_DEFINITION',:new.KPI_DEF_ID,'Deactivation time of KPI in case of Downtime'|| '(' || to_char((Select KPI_FREQ_TIME_UNIT FROM KPI_DEFINITION)) || ')',to_char(:old.DNTM_REAC_AFTER_HRS),to_char( :new.DNTM_REAC_AFTER_HRS),:new.LAST_UPDATED_BY,:new.LAST_UPDATED_DATE, decode(:new.KPI_ACTIVE_DOWNTIME,'N','This KPI has been reactivated on end of a downtime.','')); END IF; END; oracle triggers sql-insert share|improve this question edited
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 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 6.2 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.3k1384184 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 i