Mutation
Hello
CREATE TABLE "SCOTT"."SALES_ORDER_DETAIL" ( "ORDER_ID" NUMBER, "SERIAL" NUMBER, "ITEM_ID" NUMBER, "PRODUCTION_DATE" DATE, "EXPIRY_DATE" DATE, "MAX_QUANTITY" NUMBER, "MID_QUANTITY" NUMBER, "MIN_QUANTITY" NUMBER) ;
CREATE TABLE "SCOTT"."ITEM_DETAIL" ( "SERIAL" NUMBER, "ITEM_ID" NUMBER, "PRODUCTION_DATE" DATE, "EXPIRY_DATE" DATE, "QUANTITY" NUMBER) ;
I created a trigger to update (item_detail) update (sales_order_detail).
-I face an error (the table is the mutation of SALES_ORDER_DETAIL), but I do not know why?
CREATE OR REPLACE TRIGGER UPDATE_ITEM_DETAIL AFTER UPDATE OF SERIAL ON SALES_ORDER_DETAIL FOR EACH ROW DECLARE V_MAX_FACTOR NUMBER ; V_MID_FACTOR NUMBER ; FINAL_QTY NUMBER ; BEGIN SELECT MAX_TO_MIN_FACTOR , MID_TO_MIN_FACTOR INTO V_MAX_FACTOR , V_MID_FACTOR FROM STOCK WHERE ITEM_ID = :OLD.ITEM_ID ; SELECT (:OLD.MAX_QUANTITY * V_MAX_FACTOR) + (:OLD.MID_QUANTITY * V_MID_FACTOR) + (:OLD.MIN_QUANTITY) INTO FINAL_QTY FROM SALES_ORDER_DETAIL ; UPDATE ITEM_DETAIL SET QUANTITY = QUANTITY + FINAL_QTY WHERE SERIAL = :OLD.SERIAL ; END ;
?
Thank you
Maybe instead of:
- SELECT (: OLD.) MAX_QUANTITY * V_MAX_FACTOR) + (: OLD.) MID_QUANTITY * V_MID_FACTOR) + (: OLD.) MIN_QUANTITY)
- IN FINAL_QTY
- OF SALES_ORDER_DETAIL;
Simply
final_qty: = (: OLD.) MAX_QUANTITY * V_MAX_FACTOR) + (: OLD.) MID_QUANTITY * V_MID_FACTOR) + (: OLD.) MIN_QUANTITY)
Tags: Database
Similar Questions
-
Hi gurus
I have a question and according to my knowledge, I got the answer from Google, but there are a lot of different answers exist in internet so I'm not sure of my answer, I appreciate if some look on this and please correct me if you find me wrong.
What is the mutation of error?
This means that there is a wrong logic in your code, this type of error happen when you have a trigger that seeks to interrogate or manipulate same table in which this same trigger associated...
How to solve
Through Materialized View (don't know why)...
Example of
Grateful if someone give me a simple example?
Concerning
Muzz
Hello
This error occurs when you try to select data from a table and relax of time even perform the DML operation.
To avoid this you can use the autonomous_transaction pragma.
Read this.
https://decipherinfosys.WordPress.com/2009/06/22/mutating-TableTrigger-error-and-how-to-resolve-it/
-
After insert trigger mutation of error, what is the way to overcome it.
I have two tables namely profiles_answers and user_profileanswers. Based on the requirement that is: when a user inserts the answer in the table of user_profileanswers I need to calculate the weight-age of this issue with the many options available in the profiles_answers table and update this table user_profileanswers age-weight. So, for that, I wrote the following after trigger insert. But when I try to insert it throws me error mutation. As I update the table, used to insert action in the trigger. Please let me how can know I solve this problem.
create or replace
AI_weightageCaluculation TRIGGER AFTER
FOR EACH row INSERT on user_profileanswers
BEGIN
DECLARE
v_a VARCHAR2 (50);
YaeUb VARCHAR2 (50);
V_c VARCHAR2 (50);
v_d VARCHAR2 (50);
ve VARCHAR2 (50);
a_weightage NUMBER;
b_weightage NUMBER;
c_weightage NUMBER;
d_weightage NUMBER;
e_weightage NUMBER;
BEGIN
SELECT option_a, option_b, option_c, option_d, option_e IN
v_a, YaeUb, v_c, v_d, profiles_answers FROM ve
WHERE profile_questions_id =: new.profilequestion_id;
IF (v_a IS NOT NULL AND YaeUb IS NOT NULL AND v_c IS NOT NULL AND v_d IS NOT NULL AND EV IS NOT NULL) THEN
BEGIN
a_weightage: = 85;
b_weightage: = 60;
c_weightage: = 45;
d_weightage: = 30;
e_weightage: = 15;
END;
ELSIF (v_a IS NOT NULL AND YaeUb IS NOT NULL AND v_c IS NOT NULL AND v_d IS NOT NULL AND ve IS NULL) THEN
BEGIN
a_weightage: = 85;
b_weightage: = 60;
c_weightage: = 30;
d_weightage: = 15;
END;
ELSIF (v_a IS NOT NULL AND YaeUb IS NOT NULL AND v_c IS NOT NULL AND v_d IS NULL AND ve IS NULL) THEN
BEGIN
a_weightage: = 85;
b_weightage: = 45;
c_weightage: = 15;
END;
ON THE OTHER
BEGIN
a_weightage: = 85;
b_weightage: = 15;
END;
END IF;
IF: new.answer = 'A' THEN
BEGIN
UPDATE user_profileanswers
SET weightage = a_weightage
WHERE user_id =: new.user_id
AND profileanswer_id =: new.profileanswer_id
AND profilequestion_id =: new.profilequestion_id;
END;
ELSIF: new.answer = 'B' THEN
BEGIN
UPDATE user_profileanswers
SET weightage = b_weightage
WHERE user_id =: new.user_id
AND profileanswer_id =: new.profileanswer_id
AND profilequestion_id =: new.profilequestion_id;
END;
ELSIF: new.answer = 'C' THEN
BEGIN
UPDATE user_profileanswers
SET weightage = c_weightage
WHERE user_id =: new.user_id
AND profileanswer_id =: new.profileanswer_id
AND profilequestion_id =: new.profilequestion_id;
END;
ELSIF: new.answer = ' THEN
BEGIN
UPDATE user_profileanswers
SET weightage = d_weightage
WHERE user_id =: new.user_id
AND profileanswer_id =: new.profileanswer_id
AND profilequestion_id =: new.profilequestion_id;
END;
ON THE OTHER
BEGIN
UPDATE user_profileanswers
SET weightage = e_weightage
WHERE user_id =: new.user_id
AND profileanswer_id =: new.profileanswer_id
AND profilequestion_id =: new.profilequestion_id;
END;
END IF;
END;
END;
Thanks in advance.
Hmm... Why do after insertion?
CREATE OR REPLACE TRIGGER BI_weightageCaluculation
FRONT INSERT ON user_profileanswers FOR EACH ROW
BEGIN
SELECT BOX: NEW. RESPONSE
WHEN 'A' a_weight THEN
WHEN 'B' THEN b_weight
WHEN 'C' THEN c_weight
When ' THEN d_weight
Of OTHER e_weight
END
in: new.weightage
(SELECT 85 a_weight
Case option_result
WHEN 31 THEN 60
WHEN 15 THEN 60
WHEN 7 THEN 45
another 15
end b_weight
Case option_result
WHEN 31 THEN 45
WHEN 15, THEN 30
When 7 then 15
END c_weight
Case option_result
WHEN 31 THEN 30
When 15 then 15
END d_weight
Case option_result
WHEN 31 THEN 15
END e_weight
FROM (SELECT DECODE (option_a, NULL, 0, 1) +)
Decode (option_b, NULL, 0, 2) +.
Decode (option_c, NULL, 0, 4) +.
Decode (option_d, NULL, 0, 8) +.
Decode(option_e,,0,16) option_result
OF profiles_answers
WHERE profile_questions_id =: new.profilequestion_id));
END;
/
HTH
-
Can u explain someone on table mutation error pls...
Can u explain someone on table mutation error pls...
Hello
Explain what, exactly?
As always, if you get an error, check the manual for Oracle error messages: http://docs.oracle.com/database/121/ERRMG/toc.htm
Use a search engine to find related sites, such as Tom ask: https://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936
-
I was looking for the solution and find many examples, but I do not know what is the best in my option and don't understand everything.
I realized that can't do a SELECT query in the table where trigger is triggered. But I have need SELECT COUNT (col), then MAX (id) of this table, update some statistical info...
And also need to row id update, so I can't do trigger of table instead of relaxation of the line.So this is my TRIGGER:
create or replace
update_stat relaxation
AFTER UPDATE ON TABLE1 TO EACH LINE
DECLARE
juice FLOAT;
all the NUMBER;
end NUMBER;
BEGIN
IF (: old.ended <>: new.ended) THEN
SELECT COUNT (id) FROM end FROM table1 WHERE fk_table2 = new.fk_table2 AND finished = 1; -Error in the table of mutation
SELECT COUNT (id) FROM everything FROM table1 WHERE fk_table2 = new.fk_table2; -Error in the table of mutation
Juice: = ((end /all) * 100);
UPDATE table2 SET suc = success WHERE id =:new.fk_table2;
END IF;
END;
I also tried with
pragma autonomous_transaction;
trigger body....AND
commit;
But don't working right when insert more records.
Thanks, Urban
Data and structure of the example table
SQL> create table table2 2 ( 3 id integer 4 , success number 5 , constraint table2_pk primary key (id) 6 ); Table created. SQL> create table table1 2 ( 3 id integer 4 , id_t2 integer 5 , ended integer 6 , constraint table1_pk primary key (id) 7 , constraint table1_fk_id_t2 foreign key (id_t2) references table2 8 ); Table created. SQL> insert into table2(id, success) values (1, 0); 1 row created. SQL> insert into table2(id, success) values (2, 0); 1 row created. SQL> insert into table1 2 ( 3 id 4 , id_t2 5 , ended 6 ) 7 select level 8 , ceil(level/10) 9 , 0 10 from dual 11 connect by level <= 20; 20 rows created. SQL> commit; Commit complete.
Create objects to the suite
create or replace type update_stat_obj as object (id integer, id_t2 integer, ended integer) / create or replace type update_stat_tbl as table of update_stat_obj / create or replace package update_stat_pkg as g_table_1 update_stat_tbl; procedure load(p_id integer, p_id_t2 integer, p_ended integer); procedure updt; end; / show err create or replace package body update_stat_pkg as procedure load(p_id integer, p_id_t2 integer, p_ended integer) is begin if g_table_1 is null then g_table_1 := update_stat_tbl(); end if; g_table_1.extend; g_table_1(g_table_1.count) := update_stat_obj(p_id, p_id_t2, p_ended); end; procedure updt is begin merge into table2 t2 using ( select t1.id_t2 , (count(t2.id)/count(t1.id))*100 success from table1 t1 left join table(g_table_1) t2 on t1.id = t2.id and t2.ended = 1 group by t1.id_t2 ) t1 on (t2.id = t1.id_t2) when matched then update set t2.success = t1.success; g_table_1 := null; end; end; / show err create or replace trigger update_stat_row_trig after update on table1 for each row begin if (:old.ended <> :new.ended) then update_stat_pkg.load(:new.id, :new.id_t2, :new.ended); end if; end; / show err create or replace trigger update_stat_trig after update on table1 begin update_stat_pkg.updt; end; / show err
Now look for the UPDATE.
SQL> select * from table1; ID ID_T2 ENDED ---------- ---------- ---------- 1 1 0 2 1 0 3 1 0 4 1 0 5 1 0 6 1 0 7 1 0 8 1 0 9 1 0 10 1 0 11 2 0 12 2 0 13 2 0 14 2 0 15 2 0 16 2 0 17 2 0 18 2 0 19 2 0 20 2 0 20 rows selected. SQL> select * from table2; ID SUCCESS ---------- ---------- 1 0 2 0 SQL> update table1 set ended = 1 where id between 1 and 7 or id between 11 and 19; 16 rows updated. SQL> select * from table2; ID SUCCESS ---------- ---------- 1 70 2 90 SQL> select * from table1; ID ID_T2 ENDED ---------- ---------- ---------- 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 0 9 1 0 10 1 0 11 2 1 12 2 1 13 2 1 14 2 1 15 2 1 16 2 1 17 2 1 18 2 1 19 2 1 20 2 0 20 rows selected.
-
Solution for the mutation of table of error when using triggers
Hello
Could you please give the solution for the error table mutation during the use of triggers. I'll give you the simple scenario here,
I created a trigger on the employees table, whenever all DML operations takes place in the employees table, it must run the trigger body. I intentionally used also of the employees in the body of the trigger table. Please give me the solution.
Triggering factor:
create or replace trigger test_trigger
before you insert or update or delete employees
for each line
declare
an employees.first_name%type;
Start
Select first_name from people where job_id = "AD_PRES";
end;
DML statement:
Update employees set salary = 20000 where job_id = "AD_PRES" (I run this query)
Error message:
ORA-04091: table HR. Is the transfer of EMPLOYEES, the function of triggering/can not see
ORA-06512: at "HR. TEST_TRIGGER', line 4
ORA-04088: error during execution of trigger ' HR. TEST_TRIGGER'
Can anyone tell, in what other scenarios, we get this error or recursive table mutation?
Thanks in advance
Hello
When you create a trigger on a table, you cannot edit/query this table the trigger is not completed.
You can use
(1) transaction of Pragma autonomous
(2) instead of row-level trigger, you have statement-level trigger
(3) to 11 g, try with COMPOSITE trigger
Try below to avoid it (a solution):
create or replace trigger test_trigger
before you insert or update or delete employees
for each line
declare
PRAGMA AUTONOMOUS_TRANSACTION;
an employees.first_name%type;
Start
Select first_name from people where job_id = "AD_PRES";
COMMIT;
end;
-
How to solove this mutation triggers error
I have a remove after trigger on a table with 2 columns uid and appid
I check after deletion if there is no other entries in this table with the same uid, I update a flag in another table that also has the uid column.
But I get an error of mutation.
Create or replace trigger abc
after deletion on < tab1 >
referencing old as old and new like new
for each line
declare iCount number (9);
Start
Select count (*) from < tab1 > iCount
where uid =:old.uid;
If iCount = 0 then
Update flag set < tab2 > = ' no where uid =:old.uid;
end if;
end;
/
What I'm doing wrong here and how to fix it?
Thank you
YG
end;
Hello
When you create a trigger on a table, you cannot edit/query this table until the trigger/a function completed.
You can use
(1) transaction of Pragma autonomous
(2) instead of row-level trigger, you have statement-level trigger
(3) to 11 g, try with COMPOSITE trigger
-
How to troubleshoot the ora-04091: table of mutation
Hi all
Oracle version: 10g express.
case study: a class has many students, that a student has rewards.
original design:
sample data:drop table student; drop table class; create table class( clsid varchar2(9) primary key); create table student( stuid varchar2(9) primary key, clsid varchar2(9) not null references class(clsid) on delete cascade, reward varchar2(9));
issues related to the:insert into class values('cls1'); insert into student values('stu1','cls1','yes');
1. If I want to
I can put a trigger on student to check if he has that one student in class reward. This trigger must tell me error: I can not leave 'stu2' a 'Yes' on the column of the reward. But he'll lead us Oracle error: ora-04091: table of mutation. He seems to use 'after' or 'instead of' trigger can solve this problem, then how?insert into student values('stu2','cls1','yes');
2. Another way to ensure that a student in a class reward, is to change the design as:
But the question of these two tables has one foreign key to the other, is it good design?drop table student; drop table class; create table class( clsid varchar2(9) primary key, reward_stuid varchar2(9)); create table student( stuid varchar2(9) primary key, clsid varchar2(9) not null references class(cid) on delete cascade);
Thank you.
Published by: 991096 on April 11, 2013 04:56Do not use a trigger for this. This is the logic that you should include in your application as a 'check' pre before even attempting insert, or...
You use an INSERT... SELECT... statement that incorporates the audit as part of it, so the line will be inserted only if the proper test is satisfied.for example
insert into student (stuid, clsid, reward) select 'stu2', 'cls1', 'yes' from dual left outer join student s2 on (s2.clsid = 'cls1' and s2.reward = 'yes') where s2.stuid is null; -- only insert if no other student is found in same class already with reward
and then, your application can control SQL ROWCOUNT % to see if the line was inserted or not.
(Similarly, you can use a MERGE statement or clause EXISTS (NOT) or any method to do so)
-
The mutation of error in PL/SQL... can not find a solution
So I have this table:
create table weight)
ident done int refers to users.
date of dateW,
float weight,
primary key (ident, dateW)
);
I have a function called BMI who given a userid (ident) calculates the BMI (body mass index) based on the height of the user (it's on the users table) and the weight of the user is put on the table of characters. The feature works very well. Now I want to relax that when the user inserts a new weight, the trigger checks BMI of this user and see if it to reasonable values. I have this:
create or replace
relaxation BMITG
After the insertion on the WEIGHT
for each line
declare
int ident;
Start
ident: =: new.ident;
If BMI (ident) NOT BETWEEN 17 AND 25
then DBMS_OUTPUT. Put_line ('bad BMI');
end if;
end;
The trigger compiles fine, but when I try to insert weights I get:
Error from the 1 in the command line:
insert into a values (1, to_date('2013-01-30','yyyy-mm-dd'), 73) weight
Error report:
SQL error: ORA-04091: table MyDB.WEIGHTS is changing, function of triggering/can not see
ORA-06512: at "MyDB.BMI", line 6
ORA-06512: at "MyDB.BMITG", line 5
ORA-04088: error during execution of trigger 'MyDB.BMITG '.
04091 00000 - "table %s.%s is changing, function of triggering/can not see.
* Cause: A trigger (or plsql user-defined function that is referenced in)
This statement) attempted to watch (or modify) a table that has been
in the Middle being modified by the statement that shot.
* Action: Rewrite the trigger (or function) so it does not read this table.
I'm not so sure about the DBMS_OUTPUT. PUT_LINE. Which function to use to alert a user that the BMI is not good? I'll need to convey this message to a Web site through apache/php
Kind regards
DanielA level trigger line on WEIGHT cannot query the table of CHARACTERS (or call a function that queries the table of CHARACTERS). In doing so, as you've found, will trigger an error table mutation.
I'm not sure I understand why you should query the table of CHARACTERS, however. If you insert a row into the table of CHARACTERS, which is the line with the weight that you want to use for the calculation, which is probably be the line with the last DATEW or not (if you insert never back-dated lines DATEW, then the line you insert is the line you want to use for the calculation and the line with the last value DATEW).
As a general rule, I would say that the BMI function should accept a height and weight. In your trigger, you question the USERS table to get the height. Then you would spend the height and the: new.weight the new feature of the IMC.
Justin
-
error trigger table to strange mutation...
I don't think I should receive a trigger for changing table error...
As my trigger code is just acessnig value from another table... using a function.
When I change my status from open to qualified... this trigger is enabled and fails with the error table to trigger the mutation...
The trigger table mutation should only occur when you query on the same table... The table here are different... so I don't think
trigger of table mutation should shoot...
Here is the code of the trigger
create or replace
TRIGGER "CHESS".leads_after_update
before the update
ON lead
FOR EACH LINE
DECLARE
v_username varchar2 (10);
Number MNO;
BEGIN
-Find user name of the person performing the UPDATE in the table
-Insert record into the audit table
MNO: = 0;
IF: OLD. PRODUCT_tYPE = 'PTSUBSCRIBER' and: new.lead_status = "QUALIFIED" then
-update contact contactType set = 'SUBSCRIBER' where contact_no =: old.contact_nO;
-commit;
-INSERT IN CONTACT_tRANSACTION
-(TRANSACTION, CONTACT_NO, SALESMAN_cODE, ADATE)
-VALUES
-(: old.contact_nO, 'PROSPECTIVE QUALIFIED SUBSCRIBER', SYSDATE,: NEW.) EMPCODE_up);
UPDATE EMP SET MGR = find_qsubt() WHERE LEAD_NO =: NEW. LEAD_NO and mag_no = mid().
ON THE OTHER
IF: OLD. PRODUCT_tYPE = 'PTSUBSCRIBER' and: new.lead_status = "UNQUALIFIED" then
update contact set contactType = 'DISQSUBSCRIBER' where contact_no =: old.contact_nO;
UPDATE EMP SET MGR = find_uqsubt() WHERE LEAD_NO =: NEW. LEAD_NO and mag_no = mid().
END IF;
END IF;
IF: OLD. PRODUCT_TYPE = 'PTADVERTISER' AND: NEW. LEAD_STATUS = "QUALIFIED" then
-INSERTION IN MY VALUES ('ENTER DRAGONADV");
update contact contactType set = 'ADVERTISER', FLAGS = 'Y' where contact_no =: old.contact_nO;
INSERT INTO CONTACT_tRANSACTION
(CONTACT_NO, TRANSACTION, TDATE, SALESMAN_cODE)
VALUES
(: old.contact_nO, 'PROSPECTIVE ADVERTISER QUALIFIED', SYSDATE,: NEW.) EMPCODE_up);
UPDATE EMP SET MGR = find_qadvt() WHERE LEAD_NO =: NEW. LEAD_NO;
ON THE OTHER
IF: OLD. PRODUCT_TYPE = 'PTADVERTISER' AND: NEW. LEAD_STATUS = "UNQUALIFIED" then
-INSERTION IN MY VALUES ('ENTER DRAGONADV");
update contact set contactType = 'DISQADVERTISER' where contact_no =: old.contact_nO;
UPDATE EMP SET MGR = find_uqadvt() WHERE LEAD_NO =: NEW. LEAD_NO;
END IF;
END IF;
END;
This is the error message...
ORA-20505: DML error: p_rowid = 535, p_alt_rowid = LEAD_NO, p_rowid2 =, p_alt_rowid2 is. ORA-04091: table of CHESS. EMP is changing, the trigger/function cannot see ORA-06512: at "CHESS. FIND_QSUBT', line 6 ORA-06512: at "CHESS. LEADS_AFTER_UPDATE', line 23 ORA-04088: error during execution of trigger ' FAILURES. LEADS_AFTER_UPDATE'
Error failed to process row of table DRIVE.
Ok
Function...
create or replace
function
Find_qadvt return number is
mmgrno number (10);
mempno emp.empno%type;
Start
Select mmgrno from emp where mgr = 40 and mag_no = mid() empno;
Select mempno from emp where mgr = mmgrno empno and ename = "QUALIFIED";
Return mempno;
end;
Can someone guide what I'm doing wrong... The emp table is either referenced... too... So I don't think there should be a trigger of table mutation...
Any guidance will be appreciated
Published by: susf on July 9, 2012 01:46Well, you try to read EMP in the middle of an update of the EMP...
-
Code of the trigger with the error table mutation
I have 2 tables, cc_call_lists and cc_call_issues. I have a trigger on the table of cc_call_issues so that when the priority is updated I can determine how to set Issue_Priority.
Basically, the priority update for an Issue_Id I need to update the I want to watch Issue_ids of all the participating on the cc_call_lists table and determine how to update the Issue_Priority column.
Issue_Priority must always be the first priority of the table cc_call_issues for Issue_id records in the cc_call_lists table. So when I need to watch all changes priority priority values for which the Participant has records in the cc_call_lists table and take the max value priority after the record is updated.
Unfortunately, I get the following error message when the trigger is activated:
ORA-04091: table TTMS. CC_CALL_ISSUES is changing, function of triggering/can not see
ORA-06512: at «TTMS.» UPDATEISSUEPRIORITY', line 30
ORA-04088: error during execution of trigger ' TTMS. UPDATEISSUEPRIORITY'
Is there a work around which is not too complicated? Any help would be greatly appreciated.
Table: cc_call_lists
Name
-----------------
PARTICIPANT_TYPE
PARTICIPANT_ID
LAST_ACCESS_DT
LAST_ACCESS_BY
CREATE_DT
CREATE_BY
MODIFY_DT
MODIFY_BY
CALL_STATUS
CALL_PRIORITY
Table: cc_call_issues
Name
-----------------
ISSUE_ID
ISSUE_DESCR
DEACTIVATION_DT
PRIORITY
CREATE_DT
CREATE_BY
MODIFY_DT
MODIFY_BY
Trigger on cc_call_issues code:CREATE OR REPLACE TRIGGER TTMS.UpdateIssuePriority BEFORE UPDATE OF PRIORITY ON TTMS.CC_CALL_ISSUES REFERENCING NEW AS New OLD AS Old FOR EACH ROW DECLARE tmpMaxPriority number:=0; -- Get list of all participants call queue records, existing priority who also have a participant issue record with this issue code cursor c1 is select a.participant_id, a.call_priority from cc_call_lists a, cc_participant_issues b where a.participant_id = b.participant_id and b.issue_id = :new.issue_id and b.issue_status = '001' and a.call_status <> '003'; -- Not closed already BEGIN for thisone in c1 loop -- Get the existing highest priority select nvl(max(b.priority),0) into tmpMaxPriority from cc_participant_issues a, cc_call_issues b where a.issue_id = b.issue_id and a.participant_id = thisone.participant_id; -- Update it if the new priority value is higher than the existing call queue record priority if :new.priority > tmpMaxPriority then update cc_call_lists set call_priority = :new.priority where participant_id = thisone.participant_id; elsif :new.priority < tmpMaxPriority then update cc_call_lists set call_priority = tmpMaxPriority where participant_id = thisone.participant_id; end if; end loop; END UpdateIssuePriority; /
Move the level of LINE at the STATEMENT level triggers, see:
http://www.Oracle-base.com/articles/9i/mutating-table-exceptions.php
http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551198119097816936 -
Global Temp table to overcome the problem of mutation Trigger
Hi all. I need to remove a line in a table and thought that I would get around the issue of trigger mutation creating a GTB table. I created 2 different triggers. One is a level line, the other trigger a statement-level trigger.
The first trigger collects the information required to identify the row I want to delete. It is:
And the second trigger deletes the line:CREATE OR REPLACE TRIGGER Requisition_Capture AFTER UPDATE OF Delivery_Code on Supply_Items FOR EACH ROW BEGIN IF :NEW.Delivery_Code = '#' THEN INSERT INTO Requisition_Storage (Req_Code) VALUES (:NEW.Requisition_Code); END IF; END;
The GTB's stores following the information that I need to remove the line. :CREATE OR REPLACE TRIGGER SUPPLY_ITEM_RESET AFTER INSERT ON Requisition_Storage DECLARE BEGIN DELETE FROM Supply_Items r WHERE r.Requisition_Code = (SELECT t.Req_Code FROM Requisition_Storage t, Supply_Items s WHERE t.Req_Code = s.Requisition_Code) AND r.Order_Qty = 0; END;
When the Delivery_Code column is updated in the Supply_Item table and the value is reset to ' # ', that I want to capture the Requisition_Code in the Building, so I can run the statement-level trigger and remove the reset line. However, I still have a problem of error mutation. What Miss me?-- Create table create global temporary table REQUISITION_STORAGE ( req_code VARCHAR2(20) ) on commit delete rows;
The statement-level trigger would need to be a Supply_Items AFTER UPDATE TO for this to work around the problem of trigger mutation. You must ensure that your UPDATE has finished update all rows to be updated before your statement-level trigger executes.
As has been pointed out, however, the willingness to work around a trigger mutation error almost always indicates that you have a problem of data model. And you are almost always better served by setting the data model to work around the error.
Justin
-
trigger error autnomous mutation! Why not allow select in the trigger body?
case 1. a user updates the table and this user has not committed, even fire user select request, he would get an old result. but no error.
case 2. We have table x, trigger appears on the table x as soon as the table is updated to trigger fires. inside the body that we select just for table 'x' it throws error error changing table
can someone please explain why?
my example as follows:
case 1:
CREATE TABLE MyTable
(NUMBER of c1);
INSERT INTO myTable VALUES (1);
commit;
INSERT INTO myTable VALUES (2);
Select * from myTable;
C1
------------
1
case 2:
CREATE TABLE myMaxTable
(maxValue NUMBER);
CREATE TABLE MyTable
(NUMBER of c1);
INSERT INTO myMaxTable VALUES (NULL);
COMMIT;
CREATE OR REPLACE TRIGGER myTrigger
AFTER ON INSERT myTable
FOR EACH LINE
BEGIN
UPDATE myMaxTable
SET maxValue = (SELECT MAX (c1) FROM MaTable);
END;
/
INSERT INTO myTable VALUES (1);
INSERT INTO myTable VALUES (1)
*
ERROR on line 1:
ORA-04091: table HUNBUG. MYTABLE is changing, function of triggering/can not see
ORA-06512: at "HUNBUG. MON_TRIGGER', line 2
ORA-04088: error during execution of trigger ' HUNBUG. MYTRIGGER'Assume that you are doing something like this:
You have three records in the table:INSERT INTO myTable VALUES (1); INSERT INTO myTable VALUES (2); INSERT INTO myTable VALUES (3);
Then do you one insert call to do more than three:
INSERT INTO myTable SELECT c1 + 100 FROM myTable;
This last call insert inserts 3 records in your table - 101, 102 and 103.
When you have a trigger FOR EACH ROW, which will be called three times, but there is no way to predict in what order, and when the trigger will fire for example at c1 = 102, the table is the "mutation" - it is located in the heart of a change and you don't know if 101 or 103 or both is in the table. Oracle does not allow you to do a select on the table of this mutation.
When you remove the FOR EACH ROW clause, the trigger only will be called once at the end of this call to insert, moment in which the table is no longer changing and so your code will be located safely c1 max.
-
Hello gurus,
now my is - it table HT must get inserted each time that the occ_no in TB is updated when TB isnull table and table can_cont HT should not be inserted when can_cont of tuberculosis is not null; but when I try this my start trigger how to stop the mutation which is at - it differently than i cud use to develop my triggeri have two tables MAIN_TB (main table),MAIN_HT (main table history) MAIN_TB CONSIST OF C_CODE VARCHAR2; OCC_NO NUMBER; can_cont char(1); CONT_NO VARCHAR2; LOG OB_LOG; AND MAIN_HT CONSIST OF HT_OCC_NO NUMBER; C_CODE VARCHAR2 OCC_NO NUMBER; can_cont char(1); CONT_NO VARCHAR2; LOG OB_LOG;
My trigger is
How can I stop the outbreak of the mutation and how do I get my result with using the pragma autonomus transaction?CREATE OR REPLACE TRIGGER main_tr AFTER INSERT OR UPDATE OF occ_no ON main_tb REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLARE ht_occ_no NUMBER := 0; no_of_update NUMBER := 0; BEGIN BEGIN SELECT MAX (nvl (ht_occ_no, 0)) INTO ht_occ_no FROM main_ht WHERE c_code = :NEW.c_code AND cont_no = :NEW.cont_no; EXCEPTION WHEN OTHERS THEN raise_application_error (-20001, 'Error While Inserting Into MAIN_ht In MAIN_TR' || SQLERRM ); END; BEGIN SELECT mtb.LOG.no_of_update INTO no_of_update FROM main_tb mtb WHERE mtb.c_code = :OLD.c_code AND mtb.cont_no = :OLD.cont_no AND mtb.can_cont IS NULL; EXCEPTION WHEN NO_DATA_FOUND THEN no_of_update := 0; END; IF UPDATING THEN IF no_of_update = 0 THEN ht_occ_no := ht_occ_no + 1; END IF; END IF; IF INSERTING THEN IF no_of_update = 0 THEN RETURN; END IF; END IF; BEGIN INSERT INTO main_ht (ht_occ_no, c_code, occ_no, can_cont, cont_no, LOG ) VALUES (ht_occ_no, :OLD.c_code:OLD.occ_no, can_cont, cont_no, LOG ); EXCEPTION WHEN OTHERS THEN raise_application_error (-20001, 'Error While Inserting Into MAIN_ht In MAIN_TR' || SQLERRM ); END; END main_tr; /
Thank you and best regards,
friend
Edited by: most wanted! on February 5, 2012 22:49Not tested...
CREATE OR REPLACE TRIGGER main_tr AFTER INSERT OR UPDATE OF occ_no ON main_tb REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW DECLARE ht_occ_no NUMBER := 0; no_of_update NUMBER := 0; BEGIN BEGIN SELECT NVL (MAX (ht_occ_no), 0) INTO ht_occ_no FROM main_ht WHERE c_code = :NEW.c_code AND cont_no = :NEW.cont_no; EXCEPTION WHEN OTHERS THEN raise_application_error (-20001, 'Error While Inserting Into MAIN_ht In MAIN_TR' || SQLERRM ); END; IF UPDATING THEN IF :OLD.no_of_update = 0 AND :OLD.mtb.can_cont ='n' THEN ht_occ_no := ht_occ_no + 1; END IF; BEGIN INSERT INTO main_ht (ht_occ_no, c_code, occ_no, can_cont, cont_no, LOG ) VALUES (ht_occ_no, :OLD.c_code:OLD.occ_no, can_cont, cont_no, LOG ); EXCEPTION WHEN OTHERS THEN raise_application_error (-20001, 'Error While Inserting Into MAIN_ht In MAIN_TR' || SQLERRM ); END; END IF; END main_tr;
-
I thought I knew how to get Oracle to report an error Table mutation, but when I tried to do it in a demonstration today, it didn't work. Here is what I tried:
I thought that, in a level trigger line, questioning the table on which the trigger is installed, you get an error of the changing table. Same thing with INSERT, UPDATE, or DELETE. Of course, I thought I'd get the problem with DML:SQL> set serveroutput on SQL> create table test_mte (f number); Table created. SQL> insert into test_mte values (1); 1 row created. SQL> insert into test_mte values (2); 1 row created. SQL> insert into test_mte values (3); 1 row created. SQL> create or replace trigger test_mte_bt 2 before insert on test_mte 3 for each row 4 declare 5 wk_cnt number; 6 begin 7 8 select count(*) into wk_cnt from test_mte; 9 dbms_output.put_line(wk_cnt); 10 11 end test_mte_bt; 12 / Trigger created. SQL> insert into test_mte values (4); 3 1 row created.
We are on Oracle 11.1.0.7. Could something have changed in this upgrade? I'm completely confused.SQL> create or replace trigger test_mte_bt 2 before insert on test_mte 3 for each row 4 declare 5 wk_cnt number; 6 begin 7 8 update test_mte set f = 10 where f = 1; 9 dbms_output.put_line('Updated: '||SQL%ROWCOUNT); 10 11 end test_mte_bt; 12 / Trigger created. SQL> insert into test_mte values (4); Updated: 1 1 row created.
Thank you
-= ChuckIf the trigger is an INSERT... VALUES, Oracle knows this is a special case and that exactly 1 line will be inserted. This means that, indeed, a row-level trigger is no different with a statement-level trigger so the restriction on the questioning of the trigger table is not present.
If you were writing your next INSERT statement as a query - even if this query returns a single row, you will get an error because Oracle knows the syntax that you are guaranteed to get exactly one line.
SQL> insert into test_mte 2 select 5 3 from dual; insert into test_mte * ERROR at line 1: ORA-04091: table SCOTT.TEST_MTE is mutating, trigger/function may not see it ORA-06512: at "SCOTT.TEST_MTE_BT", line 4 ORA-04088: error during execution of trigger 'SCOTT.TEST_MTE_BT'
Of course, when you write the actual code, you never want to count on each insert is a single-row INSERT statement... VALUES statement so there is not much cause to take advantage of this gap in practice.
Justin
Maybe you are looking for
-
Where is the Menu bookmarks?
In Safari 10 I can only add bookmarks to the 'Favourites' section or to bookmark files, I created myself. I can't add to the bookmarks Menu more because apparently disappeared? Is this a bug? Now I can not add my favorites for the 'root' of the bookm
-
I have all the drivers up to date. 3d vision works very well when installing using the installation software but will not work with any game.
-
Hi, my computer is on its way... I would like to know how can I copy my essential before he goes... I searched my help files and can't find how to back up my computer. Thanks in advance!
-
Hello I use a mapView in my application, but I noticed - espically in OS 10.2.1 - which the mapView takes awhile to load up (in some cases more than 30 seconds) so I was wondering if it would be possible to have a loading indicator of activity should
-
PIX 501 will ios ver 6.2 come to him, with only 16ram 8flash? Thank you
Wanted to load pdm 2.1.1 firewall and VPN. Found 501 takes ver 6.2 but not to enother ram. Thank you Phil