ORA-04091, ORA-06512, ORA-04088
hi
while executing this:
SQL> insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11;
insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11
ERROR at line 1:
ORA-04091: table QA.LIB_ACCESSION_LOG is mutating, trigger/function may not
see it
ORA-06512: at "QA.TRG_ACCESSION_LOG", line 2
ORA-04088: error during execution of trigger 'QA.TRG_ACCESSION_LOG'
how can i do this insert and resolve this error. should i switch off the constraints? and what will happen when i switch on the constraints?
Check the trigger code for QA.TRG_ACCESSION_LOG.
Read here as to how the mutating error can be eliminated.
http://asktom.oracle.com/tkyte/Mutate/index.html
Similar Messages
-
ORA-04091:table XYZ is mutating,trigger/function may not see it ORA-06512
Hi everybody
i am facing mutating problem during data deletion fron XYZ table as
ORA-04091:table XYZ is mutating,trigger/function may not see it ORA-06512 at "user.procdure_name",line 39 ORA-065
i have table XYZ and have database trigger on this table
and also have procedure "user.abc" in this procedure m selecting data from xyz tableYou didn't post the actual code. I was more interested in seeing table name and the trigger body.
Anyways, mutation problem comes when you refer the same table on the trigger, on which it is based for some data manipulation on that table.
For e.g, If inside your trigger body, you are doing INSERT on the same table, then it'll definitely result in mutation problem because this trigger will be fired endlessly (as it is after insert trigger).
Please mark answer as helpful / correct, if it helps you
Navnit -
ORA-04091: is mutating, trigger/function may not see
I am getting this error
ORA-04091: table SATURN.SARQUAN is mutating, trigger/function may not see it
ORA-06512: at "BANINST1.F_GETSARQUANSEQNO", line 24
ORA-06512: at "BANINST1.F_GETSARQUANSEQNO", line 30
I am trying to do this insert
INSERT INTO sarquan
(sarquan_pidm,sarquan_term_code_entry,sarquan_seqno,
sarquan_appl_no, sarquan_question,
sarquan_answer, sarquan_activity_date,
sarquan_user_id
SELECT spriden_pidm,'201090',BANINST1.F_GETSARQUANSEQNO(spriden_pidm,'201090','1'),'1',
'Would you prefer September admission?',
DECODE (szcasup_sept_adm, 'Y', 'Yes', 'N', 'No'),sysdate,'rmanoei'
FROM saturn_midd.szcasup, saturn.spriden
WHERE spriden_id = szcasup_common_appl_id
AND spriden_ntyp_code = 'CAPP'
AND ( szcasup_sept_adm IS NOT NULL
OR szcasup_feb_adm IS NOT NULL
OR szcasup_interview IS NOT NULL
AND NOT EXISTS (
SELECT *
FROM sarquan
WHERE sarquan_pidm = spriden_pidm
AND spriden_ntyp_code = 'CAPP'
AND sarquan_term_code_entry = '201090');
I got data when I ran just the select statement, none of the records have data in the sarquan table.
I got data when I select from this function
,BANINST1.F_GETSARQUANSEQNO(spriden_pidm,'201090','1'),'1'
Any ideas?
Edited by: peace4all on Aug 12, 2009 4:49 PMI can not drop the trigger, I don't own the trigger, it is in production, SARQUAN is a production table
Now I am getting this error ORA-04091: table SATURN.SARQUAN is mutating, trigger/function may not see it
ORA-06512: at "BANINST1.F_GETSARQUANSEQNO", line 24
ORA-06512: at "BANINST1.F_GETSARQUANSEQNO", line 30
ORA-06512: at "SATURN.ST_SARQUAN_INSERT_ROW", line 2
ORA-04088: error during execution of trigger 'SATURN.ST_SARQUAN_INSERT_ROW'
when I do the following
I know that this pidm does not have any records in the table SARQUAN
spriden_pidm = 2287953
So I try to do a simple insert, not using the function, now I am hardcoding the seq, I know it needs to be 1 since there are not records in that table yet,
the sequence go by pidm
INSERT INTO saturn.sarquan
sarquan_pidm,
sarquan_seqno,
sarquan_term_code_entry,
sarquan_appl_no,
sarquan_question,
sarquan_answer,
sarquan_activity_date,
sarquan_user_id
SELECT spriden_pidm,'1',
'201090','1',
'Would you prefer September admission?',
DECODE (szcasup_sept_adm, 'Y', 'Yes', 'N', 'No'),sysdate,'recheverri'
FROM saturn_midd.szcasup, saturn.spriden
WHERE spriden_id = szcasup_common_appl_id
AND spriden_ntyp_code = 'CAPP'
and spriden_pidm = 2287953
AND ( szcasup_sept_adm IS NOT NULL
OR szcasup_feb_adm IS NOT NULL
OR szcasup_interview IS NOT NULL
AND NOT EXISTS (
SELECT *
FROM saturn.sarquan
WHERE sarquan_pidm = spriden_pidm
AND spriden_ntyp_code = 'CAPP'
AND sarquan_term_code_entry = '201090');
Edited by: peace4all on Aug 13, 2009 5:35 AM -
How to get around ora-ORA-04091: table SSBOSS.SSTRMAST is mutating, trigger
hi,
Does anyone know how one would get around this problem please ?
Here is my dbase trig:
CREATE OR REPLACE TRIGGER SSBOSS.new_not_greater_than_net
BEFORE INSERT OR UPDATE OF newrent ON SSBOSS.SSTRMAST
REFERENCING NEW AS new OLD AS old
FOR each row
DECLARE
not_permitted EXCEPTION;
vnum number := ssboss.nik_f;
BEGIN
IF :new.NEWRENT > vnum then
--AND :old.DELETED = 'N' THEN
RAISE not_permitted;
END IF;
EXCEPTION
WHEN not_permitted THEN
RAISE_APPLICATION_ERROR
(-20001, 'NEWRENT:'||:new.newrent||' '||'OLDRENT:'||' '||:old.netrent||'Action not permitted. Contribution (sstrmast.newrent) value '
||:new.NEWRENT
||' exceeds GROSS rental value (sstrmast.netrent) ');
END;
Here is my problem:
SQL> update sstrmast set newrent = 11;
update sstrmast set newrent = 11
ERROR at line 1:
ORA-04091: table SSBOSS.SSTRMAST is mutating, trigger/function may not see it
ORA-06512: at "SSBOSS.NIK_F", line 4
ORA-06512: at "SSBOSS.NEW_NOT_GREATER_THAN_NET", line 4
ORA-04088: error during execution of trigger 'SSBOSS.NEW_NOT_GREATER_THAN_NET'
I understand why but not how to correct?
Thanks,
nikolia.Hello,
This problem as you might be knowing occurs when you try to select the data from the same table on which the trigger is written. Also this problem is only with the row level trigger and not with the statement level trigger. However the limitation of the statement level trigger is it can not refer to :NEW or :OLD. So now the solution is to capture the value of :NEW or :OLD in the row level trigger (no select statement here) and store it in some global variable. And how do you get the global variable? Using package specification ! a variable declared in a package specification is global in nature. Then use the value so stored in the statement level trigger in the select statement. It will work. Other solution is to use pragma autonomous transaction. Try and let us know. All the best.
Regards -
Hi,
I have a trigger which executes a stored procedure.
Trigger
=======
CREATE OR REPLACE TRIGGER mhubadmin.call_proc_ratesheet_new
after INSERT OR delete ON mhubadmin.pvt_br_ratesheet
FOR EACH ROW
declare
var_orgid number;
begin
if inserting then
select org_child_id into var_orgid from business_relationship where br_id=:new.br_id;
mhubadmin.proc_ratesheet_new(var_orgid);
else
select org_child_id into var_orgid from business_relationship where br_id=:old.br_id;
mhubadmin.proc_ratesheet_new(var_orgid);
end if;
end;
Stored Procedure
==============
CREATE OR REPLACE PROCEDURE proc_ratesheet_new(var_orgid in number)
IS
cursor c3 is select distinct(purs.user_id) from hubuser hu
inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid;
cursor c1(varUser_id number) is select purs.user_id,purs.ratesheet_id from hubuser hu
inner join PVT_USER_RATESHEET purs on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid and purs.USER_ID=varUser_id;
cursor c2(varUser_id number) is select hu.user_id,pbr.ratesheet_id from HUBUSER hu
inner join BUSINESS_RELATIONSHIP br on hu.ORG_ID=br.ORG_CHILD_ID
inner join PVT_BR_RATESHEET pbr on br.BR_ID=pbr.BR_ID
where hu.user_id in(select distinct(purs.USER_ID) from hubuser hu
inner join PVT_USER_RATESHEET purs
on hu.USER_ID=purs.USER_ID
where hu.ORG_ID=var_orgid) and hu.user_id=varUser_id;
foundFlag boolean;
BEGIN
for c3var in c3 loop
for c2var in c2(c3var.user_id) loop
foundFlag:=false;
for c1var in c1(c3var.user_id) loop
if c2var.ratesheet_id=c1var.ratesheet_id then
foundFlag:=true;
exit;
end if;
end loop;
if foundFlag=False then
insert into pvt_user_ratesheet (username_ratesheet_id,user_id,ratesheet_id) values (SEQ_USER_RATESHEET.nextval,c3var.user_id,c2var.ratesheet_id);
end if;
end loop;
end loop;
for c3var in c3 loop
for c1var in c1(c3var.user_id) loop
foundFlag:=false;
for c2var in c2(c3var.user_id) loop
if c1var.ratesheet_id=c2var.ratesheet_id then
foundFlag:=true;
exit;
end if;
end loop;
if foundFlag=False then
delete from pvt_user_ratesheet where user_id=c3var.user_id and ratesheet_id=c1var.ratesheet_id;
end if;
end loop;
end loop;
--EXCEPTION
--- WHEN OTHERS THEN
--- DBMS_OUTPUT.put_line (SQLCODE||' '|| SQLERRM);
END;
But while firing this trigger I am getting an error like this,
ORA-04091: table MHUBADMIN.PVT_BR_RATESHEET is mutating, trigger/function may not see it
ORA-06512: at "MHUBADMIN.PROC_RATESHEET_NEW", line 14
ORA-06512: at "MHUBADMIN.PROC_RATESHEET_NEW", line 25
ORA-06512: at "MHUBADMIN.CALL_PROC_RATESHEET_NEW", line 6
ORA-04088: error during execution of trigger 'MHUBADMIN.CALL_PROC_RATESHEET_NEW'
Regards,
MathewYes, and I'm reading this on a computer screen!
What functional requirement are you trying to achieve?
And have you googled? If so, you would have found this
http://asktom.oracle.com/tkyte/Mutate/index.html
Cheers,
Colin -
ORA-04091: table QA.LIB_ACCESSION_LOG is mutating
hi
while executing this:
SQL> insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11;
insert into LIB_ACCESSION_LOG select * from LIB_ACCESSION_LOG11
ERROR at line 1:
ORA-04091: table QA.LIB_ACCESSION_LOG is mutating, trigger/function may not
see it
ORA-06512: at "QA.TRG_ACCESSION_LOG", line 2
ORA-04088: error during execution of trigger 'QA.TRG_ACCESSION_LOG'
how can i do this insert and resolve this error. should i switch off the constraints? and what will happen when i switch on the constraints?ORA-04091, ORA-06512, ORA-04088.
-
ORA-04091: table AM is mutating, trigger/function may not see it
I create this trigger:
CREATE OR REPLACE TRIGGER pr_test
after insert ON AM
FOR EACH ROW
declare
appo_pr varchar2(64):= null;
BEGIN
select name
into appo_pr
from AS
where AS_ID=:new.AS_ID;
insert into AM (name) values (appo_pr);
END pr_test;
I insert before a new AS_ID and name in tab AS but when I insert a new record in tab AM I get this error:
ORA-04091: table AM is mutating, trigger/function may not see it
ORA-06512: at PR_TEST", line 11
ORA-04088: error during execution of trigger PR_TEST'
I'd like to create a trigger that when I insert a new record in AM It verify the value in col name of AS and insert this value in col name of AM.
What I wrong in this trigger??
How can I modify it??
Thanks
RafTry this:
CREATE OR REPLACE TRIGGER pr_test
before insert ON AM
FOR EACH ROW
declare
appo_pr AS.name%TYPE;
BEGIN
select name
into appo_pr
from AS
where AS_ID = :new.AS_ID;
:new.name = appo_pr;
END pr_test; -
ORA-04091: table blah is mutating, trigger/function may not see it
ORA-04091: table blah is mutating, trigger/function may not see it
ORA-06512: at "AOLALERE.CHK_FOR_POST", line 7
ORA-06512: at "AOLALERE.CHK_FOR_POST", line 20
ORA-06512: at "AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE", line 14
ORA-04088: error during execution of trigger 'AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE'
TRIGGER preproddta_f41021_after_update
after insert or update
on preproddta.f41021
for each row
declare
--nothing to declare
--pragma autonomous_transaction;
l_lipqoh preproddta.f41021.lipqoh%type;
l_lipcom preproddta.f41021.lipcom%type;
l_lihcom preproddta.f41021.lihcom%type;
l_lilots preproddta.f41021.lilots%type;
l_lilocn preproddta.f41021.lilots%type;
l_lilotn preproddta.f41021.lilots%type;
l_quantity_avail f41021_audit.quantity_avail%type;
l_rec_chk f41021_audit.liitm%type;
begin
--chk_for_post(:new.limcu,:new.liitm);
--if :old.limcu <> ' GBD001' then return; end if;
if :old.lipqoh = :new.lipqoh then
l_lipqoh := :old.lipqoh;
else
l_lipqoh := :new.lipqoh;
end if;
if :old.lipcom = :new.lipcom then
l_lipcom := :old.lipcom;
else
l_lipcom := :new.lipcom;
end if;
if :old.lihcom = :new.lihcom then
l_lihcom := :old.lihcom;
else
l_lihcom := :new.lihcom;
end if;
if :old.lilots = :new.lilots then
l_lilots := :old.lilots;
else
l_lilots := :new.lilots;
end if;
if l_lilots <> ' ' then
l_quantity_avail := - (l_lipcom - l_lihcom);
else
l_quantity_avail := l_lipqoh - (l_lipcom + l_lihcom);
end if;
l_rec_chk := rec_chk(:old.limcu,:old.liitm,l_lilots);
if l_rec_chk is not null then
begin
update f41021_audit
set lipqoh = l_lipqoh,
lipcom = l_lipcom,
lihcom = l_lihcom,
quantity_avail = l_quantity_avail
where limcu = :old.limcu
and liitm = :old.liitm
and lilotn = :old.lilotn
and lilocn = :old.lilocn
and lilots = l_lilots;
end;
else
-- insert record into audit table
begin
insert into f41021_audit
(limcu,
liitm,
lipqoh,
lipcom,
lihcom,
lilots,
lilotn,
lilocn,
quantity_avail)
values
(:old.limcu,
:old.liitm,
l_lipqoh,
l_lipcom,
l_lihcom,
l_lilots,
:old.lilotn,
:old.lilocn,
l_quantity_avail);
end;
end if;
end;
create or replace procedure chk_for_post(p_limcu in varchar2,
p_liitm in number)
is
cursor get_bra_qa(p_limcu in varchar2,
p_liitm in number)is
select liitm,
(sum(lipqoh) - sum(lipcom + lihcom)) qual_avail
from preproddta.f41021 a, preproddta.f4101 b
where limcu = p_limcu
and liitm = imitm
and liitm = p_liitm
group by liitm,imdsc1;
l_bra_qa get_bra_qa%rowtype;
l_itm_bran_qa t_f41021_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
begin
open get_bra_qa(p_limcu,p_liitm);
fetch get_bra_qa into l_bra_qa;
close get_bra_qa;
if l_itm_bran_qa.quantity_avail is null then ---This indicate that there is no record for
---quantity available for the item based on the branch .
l_itm_bran_qa := new t_f41021_itm_bran_qa(p_liitm);
begin
l_itm_bran_qa.liitm := p_liitm;
l_itm_bran_qa.limcu := p_limcu;
l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
l_itm_bran_qa.add_it;
commit;
end;
else
l_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
if l_itm_bran_qa.quantity_avail = l_bra_qa.qual_avail then
null; return;
else
begin
l_itm_bran_qa.liitm := p_liitm;
l_itm_bran_qa.limcu := p_limcu;
l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
l_itm_bran_qa.send_to_DB;
commit;
end;
end if;
end if;
end;Thanks,
I comment it out cos it was causing the problem this is the code:
The following error has occurred:
ORA-04091: table PREPRODDTA.F41021 is mutating, trigger/function may not see it
ORA-06512: at "AOLALERE.CHK_FOR_POST", line 7
ORA-06512: at "AOLALERE.CHK_FOR_POST", line 20
ORA-06512: at "AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE", line 98
ORA-04088: error during execution of trigger 'AOLALERE.PREPRODDTA_F41021_AFTER_UPDATE'
TRIGGER preproddta_f41021_after_update
after insert or update
on preproddta.f41021
for each row
declare
--nothing to declare
--pragma autonomous_transaction;
l_lipqoh preproddta.f41021.lipqoh%type;
l_lipcom preproddta.f41021.lipcom%type;
l_lihcom preproddta.f41021.lihcom%type;
l_lilots preproddta.f41021.lilots%type;
l_lilocn preproddta.f41021.lilots%type;
l_lilotn preproddta.f41021.lilots%type;
l_quantity_avail f41021_audit.quantity_avail%type;
l_rec_chk f41021_audit.liitm%type;
begin
--if :old.limcu <> ' GBD001' then return; end if;
if :old.lipqoh = :new.lipqoh then
l_lipqoh := :old.lipqoh;
else
l_lipqoh := :new.lipqoh;
end if;
if :old.lipcom = :new.lipcom then
l_lipcom := :old.lipcom;
else
l_lipcom := :new.lipcom;
end if;
if :old.lihcom = :new.lihcom then
l_lihcom := :old.lihcom;
else
l_lihcom := :new.lihcom;
end if;
if :old.lilots = :new.lilots then
l_lilots := :old.lilots;
else
l_lilots := :new.lilots;
end if;
if l_lilots <> ' ' then
l_quantity_avail := - (l_lipcom - l_lihcom);
else
l_quantity_avail := l_lipqoh - (l_lipcom + l_lihcom);
end if;
l_rec_chk := rec_chk(:old.limcu,:old.liitm,l_lilots);
if l_rec_chk is not null then
begin
update f41021_audit
set lipqoh = l_lipqoh,
lipcom = l_lipcom,
lihcom = l_lihcom,
quantity_avail = l_quantity_avail
where limcu = :old.limcu
and liitm = :old.liitm
and lilotn = :old.lilotn
and lilocn = :old.lilocn
and lilots = l_lilots;
end;
else
-- insert record into audit table
begin
insert into f41021_audit
(limcu,
liitm,
lipqoh,
lipcom,
lihcom,
lilots,
lilotn,
lilocn,
quantity_avail)
values
(:old.limcu,
:old.liitm,
l_lipqoh,
l_lipcom,
l_lihcom,
l_lilots,
:old.lilotn,
:old.lilocn,
l_quantity_avail);
end;
end if;
chk_for_post(:new.limcu,:new.liitm);
return;
end;
create or replace procedure chk_for_post(p_limcu in varchar2,
p_liitm in number)
is
cursor get_bra_qa(p_limcu in varchar2,
p_liitm in number)is
select liitm,
(sum(lipqoh) - sum(lipcom + lihcom)) qual_avail
from preproddta.f41021 a, preproddta.f4101 b
where limcu = p_limcu
and liitm = imitm
and liitm = p_liitm
group by liitm,imdsc1;
l_bra_qa get_bra_qa%rowtype;
l_itm_bran_qa t_f41021_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
begin
open get_bra_qa(p_limcu,p_liitm);
fetch get_bra_qa into l_bra_qa;
close get_bra_qa;
if l_itm_bran_qa.quantity_avail is null then ---This indicate that there is no record for
---quantity available for the item based on the branch .
l_itm_bran_qa := new t_f41021_itm_bran_qa(p_liitm);
begin
l_itm_bran_qa.liitm := p_liitm;
l_itm_bran_qa.limcu := p_limcu;
l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
l_itm_bran_qa.add_it;
commit;
end;
else
l_itm_bran_qa := t_f41021_itm_bran_qa.initialize(p_liitm);
if l_itm_bran_qa.quantity_avail = l_bra_qa.qual_avail then
null; return;
else
begin
l_itm_bran_qa.liitm := p_liitm;
l_itm_bran_qa.limcu := p_limcu;
l_itm_bran_qa.quantity_avail := l_bra_qa.qual_avail;
l_itm_bran_qa.send_to_DB;
commit;
end;
end if;
end if;
end;
Please sugesst any work around. I need to call calculate changes based on the insert or updates -
ORA-04091: table is mutating, trigger/function may no
Hi all,
I'm trying to create a trigger, but I got the following:
ERROR at line 1:
ORA-04092: cannot ROLLBACK in a trigger
ORA-06512: at "PKG_PROJ", line 63
ORA-04091: table TBL_DATA is mutating, trigger/function may not see it
ORA-06512: at "T$D_INS_TDATA", line 4
ORA-04088: error during execution of trigger 'T$D_INS_TDATA'My trigger is:
CREATE OR REPLACE TRIGGER T$D_INS_TDATA
AFTER INSERT ON TBL_DATA
FOR EACH ROW
DECLARE
BEGIN
PKG_PROJ.P$INSERT(:NEW.ID);
COMMIT;
END;
/Where meu procedure is:
PROCEDURE P$INSERT
P_ID IN TBL_DATA.ID%TYPE
AS
BEGIN
INSERT INTO TBL_DETAIL
ID_DETAIL, DT_DETAIL, OBS,
SELECT SEQ_DETAIL.NEXTVAL, SYSDATE, 'INSERT TRIGGER TEST'
FROM TBL_DATA DC
AND DC.ID = P_ID
COMMIT WORK;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE_APPLICATION_ERROR(-20102, 'PKG_PROJ.P$INSERT: ' || SQLERRM);
END P$INSERT;Somebody can help me???
thanx!!!! :-)Tad,
I believe you're performing SELECT on the triggering table in the PL/SQL block. In simple words, you're trying to change the information of a table the TRIGGER is created for and you're trying to read data from the same table.
I suggest that you use PL/SQL pragma autonomous_transaction to resolve this, for as per Oracle documentation "The AUTONOMOUS_TRANSACTION pragma instructs the PL/SQL compiler to mark a routine as autonomous (independent). An autonomous transaction is an independent transaction started by another transaction, the main transaction. Autonomous transactions let you suspend the main transaction, do SQL operations, commit or roll back those operations, then resume the main transaction."
Furthermore, you can also refer to the following discussion by Thomas Kyte for further understanding of mutating tables:
Avoiding Mutating Tables
http://asktom.oracle.com/tkyte/Mutate/
Hope this helps.
Regards,
Naveed. -
ORA-04091: table ...is mutating, trigger/function may
when I run a delete on this table I have the error
ORA-04091: table MICRODEV.T086_LIEN_INSC is mutating, trigger/function may not see it
ORA-06512: at "MICRODEV.TG_DEL_T086_LIEN_INSC", line 5
ORA-04088: error during execution of trigger 'MICRODEV.TG_DEL_T086_LIEN_INSC'
How Can I workaround it
CREATE OR REPLACE TRIGGER "MICRODEV"."TG_DEL_T086_LIEN_INSC"
BEFORE
DELETE ON "MICRODEV"."T086_LIEN_INSC" FOR EACH ROW DECLARE lNbRows NUMBER(1);
BEGIN
IF :OLD.CO_PART_DNOM_SOC = 'DS' THEN
SELECT 1 INTO lNbRows
FROM T086_LIEN_INSC
WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
AND NO_INSC = :OLD.NO_INSC
AND CO_PART_DNOM_SOC <> 'PA';
IF lNbRows = 1 THEN
raise_application_error(-20100, 'TRIGGER On Delete (T086_LIEN_INSC)');
END IF;
SELECT 2 INTO lNbRows
FROM T086_LIEN_INSC
WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
AND NO_INSC = :OLD.NO_INSC
AND CO_PART_DNOM_SOC = 'PA';
IF lNbRows = 2 THEN
raise_application_error(-20101, 'TRIGGER On Delete (T086_LIEN_INSC)');
END IF;
END IF;
END;when I run a delete on this table I have the error
ORA-04091: table MICRODEV.T086_LIEN_INSC is mutating, trigger/function may not see it
ORA-06512: at "MICRODEV.TG_DEL_T086_LIEN_INSC", line 5
ORA-04088: error during execution of trigger 'MICRODEV.TG_DEL_T086_LIEN_INSC'
How Can I workaround it
CREATE OR REPLACE TRIGGER "MICRODEV"."TG_DEL_T086_LIEN_INSC"
BEFORE
DELETE ON "MICRODEV"."T086_LIEN_INSC" FOR EACH ROW DECLARE lNbRows NUMBER(1);
BEGIN
IF :OLD.CO_PART_DNOM_SOC = 'DS' THEN
SELECT 1 INTO lNbRows
FROM T086_LIEN_INSC
WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
AND NO_INSC = :OLD.NO_INSC
AND CO_PART_DNOM_SOC <> 'PA';
IF lNbRows = 1 THEN
raise_application_error(-20100, 'TRIGGER On Delete (T086_LIEN_INSC)');
END IF;
SELECT 2 INTO lNbRows
FROM T086_LIEN_INSC
WHERE NO_SEQ_LIEN_DNOM = :OLD.NO_SEQ_LIEN_INSC
AND NO_INSC = :OLD.NO_INSC
AND CO_PART_DNOM_SOC = 'PA';
IF lNbRows = 2 THEN
raise_application_error(-20101, 'TRIGGER On Delete (T086_LIEN_INSC)');
END IF;
END IF;
END; -
hi,
i made a trigger on a table fire on after insertion but i m having these error so plz try to solve it.
CREATE OR REPLACE TRIGGER TG1
AFTER INSERT
ON MASTER
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
COUNT NUMBER;
BEGIN
SELECT COUNT(*) INTO COUNT FROM MASTER
WHERE P_ID =:NEW.P_ID ;
BEGIN
IF COUNT=1 THEN
UPDATE MASTER SET PCODE =:COUNT;
END IF;
IF COUNT=2 THEN
UPDATE MASTER SET PCODE =:COUNT+1;
END IF;
END;
END;
ORA-04091: table master is mutating, trigger/function may
not see it
ORA-06512: at "TG1", line 5
ORA-04088: error during execution of trigger 'TG1'You don't understand mutating tables and how to avoid them. Nor do you understand how multi-user systems work. Finally you appear not to understand how to use the documentation Given all that, your soubriquet is overambitious. You might want to consider a more modest handle.
As for the specifics, how to avoid the ORA-4091 error, the root cause is that we cannot select on the table in question in a FOR EACH ROW trigger. You seem to be after an incremental count, presumably as unique identifier. This is the wrong approach: use a sequence and stop worrying about gaps.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Trigger to copy records from one table to another; ORA-04091:
Hello,
I'm trying to create a trigger that will move data from one table to another.
I have two tables (Trial1, Trial2) Both of them contains the same attributes (code, c_index)
I want to move each new record inserted in (code in Trial1) to (code in Trial2)
This is my trigger:
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
select :new.code from Trial1;
end;It compiled, but when I insert new (code) record into (Trial1) it display this error:
Error report:
SQL Error: ORA-04091: table STU101.TRIAL1 is mutating, trigger/function may not see it
ORA-06512: at "STU101.TRG_MOVE_TO_TRIAL2", line 3
ORA-04088: error during execution of trigger 'STU101.TRG_MOVE_TO_TRIAL2'
04091. 00000 - "table %s.%s is mutating, trigger/function may not see it"
*Cause: A trigger (or a user defined plsql function that is referenced in
this statement) attempted to look at (or modify) a table that was
in the middle of being modified by the statement which fired it.
*Action: Rewrite the trigger (or function) so it does not read that table.I know what does this error mean, but I don't how to fix the error.
I tried to change the (After insert on Trial1) to be (Before insert on Trial1); that worked, but not in the right way. When I insert new value into (code in Trial1) and refreshed Trial2 table, as much as records I have in Trial 2 they will be duplicated. E.g.
Trial2
code
111
222
333when I insert in Trial1
Trial1
code
444
Trial2 will be:
code
111
222
333
444
444
444Can you please tell me how to solve this issue?
Regards,
Edited by: 1002059 on Apr 23, 2013 5:36 PMYou should not select from Trial1 - you have the data already. Just insert that value.
Create or replace trigger trg_move_to_trial2
After insert on Trial1
for each row
begin
insert into Trial2 (code)
values (:new.code);
end; regards,
David -
Hello alll,
i have the following Triggered
CREATE OR REPLACE FUNCTION SUM_QUANTITY
RETURN NUMBER
IS
v_sum_qty NUMBER(19,5);
BEGIN
SELECT SUM(ITEM_QTY)
INTO v_sum_qty
FROM WH_T_ITEMS ,WH_TRANSACTIONS
WHERE WH_T_ITEMS.STORE_ID = WH_TRANSACTIONS.STORE_ID
AND WH_T_ITEMS.TRANSACTION_SERIAL = WH_TRANSACTIONS.TRANSACTION_SERIAL
AND TYPE_ID IN(1,2,3,4,5) ; -- all adds involved the opening balance
RETURN v_sum_qty;
EXCEPTION
WHEN OTHERS THEN RAISE;
END SUM_QUANTITY;
Function created.when am using the form 2 normally insert in i have the after commit.
ORA-04091: table DB.WH_T_ITEMS is mutating, trigger/function may not see it
ORA-06512: at "DB.SUM_QUANTITY", line 19
ORA-06512: at "DB.BALANCE_QUANTITY", line 8
ORA-04088: error during execution of trigger 'DB.BALANCE_QUANTITY'Pls Guide me how 2 simply over-ride this problem.
Regards,
Abdetu...Thanks i have read it and used the Before Insert Trigger i got ride of the problem but with now results
i need 2 read it in depth but time is limited 2 the task,1 friend once told me 2 use a twin table as a transite 2 manipulate the functionality of my bussiness
i did and it worked fine but i was just wanted 2 know other experienced people they offered many worked solutions but they didn't agree with each other.
So u know...
am little confused which best solution 2 use so i posted as an Ora not the name of the Ora
hope someone help or suggest a help.
Regards,
Abdetu... -
I am trying to follow the example in Oracle HTML DB User's guide to send an e-mail to a just entered email address.
The trigger seems to compile and be valid but when I enter a record I get:
ORA-04091: table FOLKLORE.SERVICEREQUESTS is mutating, trigger/function may not see it ORA-06512: at "FOLKLORE.SERVICEREQUESTS_T1", line 3 ORA-04088: error during execution of trigger 'FOLKLORE.SERVICEREQUESTS_T1'
My trigger looks like:
Schema FOLKLORE
Trigger Name SERVICEREQUESTS_T1
Trigger Type AFTER EACH ROW
Triggering Event INSERT
Table Schema FOLKLORE
Base Object Type TABLE
Table Name SERVICEREQUESTS
Column Name (null)
Referencing Names REFERENCING NEW AS NEW OLD AS OLD
When Clause (null)
Status ENABLED
Description "SERVICEREQUESTS_T1" AFTER insert on "SERVICEREQUESTS" for each row
Action Type PL/SQL
Trigger Body
begin
if (inserting and :new.srid is not null) then
for c1 in
(SELECT REQUESTOREMAIL FROM SERVICEREQUESTS WHERE SRID = :new.srid)
loop
if c1.REQUESTOREMAIL is not null then
htmldb_mail.send(
p_to => c1.REQUESTOREMAIL,
p_from => c1.REQUESTOREMAIL,
p_body => 'Your service request has been submitted for review',
p_subj => 'Service Request');
end if;
end loop;
end if;
end;
And the table looks like:
SQL> desc servicerequests;
Name Null? Type
SRID NOT NULL NUMBER(5)
DATEOFREQUEST NOT NULL DATE
DATENEEDED DATE
REQUESTOR NOT NULL VARCHAR2(40)
REQUESTOREMAIL NOT NULL VARCHAR2(50)
REQUESTORPHONE NOT NULL VARCHAR2(4)
REQUESTORPROGRAM NOT NULL VARCHAR2(50)
PROJECTTITLE NOT NULL VARCHAR2(50)
PROJSCOPE NOT NULL CLOB
PRJJUSTIFICATION NOT NULL VARCHAR2(3000)
ESTCOST NUMBER(5,2)
BUDGETED CHAR(1)
FUNDSOURCE VARCHAR2(50)
DEVID NOT NULL NUMBER(2)
DEVOTHER VARCHAR2(50)
NUMBEROFUSERS NUMBER(3)
CREATEDATE NOT NULL DATE
STATUS NOT NULL VARCHAR2(20)
STATUSDATE NOT NULL DATEIt might be better to create a PL/SQL Package api to to this table. Let it handle the insert and the email. You could use "insert into ... returning id into l_id" to get back the pk from the insert and still be able to use it in your email. You also wouldn't have to worry about the mutating triggers issue.
Just a thought,
Tyler -
SQL, PL/SQL functions, and ORA-04091 table is mutating
Dears,
Recently a question came up in an Oracle French forum about an insert/select that is throwing ORA-04091: table xxxx is mutating, trigger/function may not see it error in 11g while the same insert/select was working very well in 10g. The original poster gave a scenario that is easily reproducible. I am wondering what database release is correct the one throwing the error(11g) or the other one accepting the insert/select(10g)?
*10g*
mhouri.world > select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
mhouri.world > create table t_read_consistency (id number, vc varchar2(15), primary key (id));
Table created.
mhouri.world > insert into
2 t_read_consistency
3 select
4 rownum id,
5 rpad('a',15,'a')
6 from
7 dual
8 connect by
9 level<=1000;
1000 rows created.
mhouri.world > commit;
Commit complete.
mhouri.world > create or replace function f_read_consistency return varchar2
2 as
3 lv_vc t_read_consistency.vc%type;
4 begin
5 select trc.vc
6 into lv_vc
7 from t_read_consistency trc
8 where trc.id = 70 ;
9 return lv_vc;
10 end f_read_consistency;
11 /
Function created.
mhouri.world >insert into
2 t_read_consistency (id, vc)
3 select
4 1001
5 ,f_read_consistency
6 from dual;
,f_read_consistency
ERROR at line 5:
ORA-04091: table MHOURI.T_READ_CONSISTENCY is mutating, trigger/function may not see it
ORA-06512: at "MHOURI.F_READ_CONSISTENCY", line 5
_11g_
mohamed@mhouri> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
mohamed@mhouri> create table t_read_consistency (id number, vc varchar2(15), primary key (id));
Table created.
mohamed@mhouri> insert into
2 t_read_consistency
3 select
4 rownum id,
5 rpad('a',15,'a')
6 from
7 dual
8 connect by
9 level<=1000;
1000 rows created.
mohamed@mhouri> create or replace function f_read_consistency return varchar2
2 as
3 lv_vc t_read_consistency.vc%type;
4 begin
5 select trc.vc
6 into lv_vc
7 from t_read_consistency trc
8 where trc.id = 70 ;
9 return lv_vc;
10 end f_read_consistency;
11 /
Function created.
mohamed@mhouri> insert into
2 t_read_consistency (id, vc)
3 select
4 1001
5 ,f_read_consistency
6 from dual;
,f_read_consistency
ERROR at line 5:
ORA-04091: table MOHAMED.T_READ_CONSISTENCY is mutating, trigger/function may
not see it
ORA-06512: at "MOHAMED.F_READ_CONSISTENCY", line 5 So far so good. Same behaviour for both releases. But let's bring a small change to the PL/SQL function to be as close as the example given in the French Forum
_10g where the select/insert was working without error_:
mhouri.world > select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
mhouri.world > create type t_read_cs as object (id number,vc varchar2(15));
2 /
Type created.
mhouri.world > create type t_read_cs_tab as table of t_read_cs;
2 /
Type created.
mhouri.world > create or replace function f_read_consistency_tab
2 return t_read_cs_tab
3 as
4 lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
5 j binary_integer := 0;
6 begin
7 for x in (select
8 id,
9 vc
10 from t_read_consistency trs
11 where trs.id <= 10
12 ) loop
13
14 j := j +1;
15 lc_t_read_cs_tab.extend;
16 lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
17 end loop;
18 RETURN lc_t_read_cs_tab;
19 end f_read_consistency_tab;
20 /
Function created.
mhouri.world > select count(1) from t_read_consistency;
COUNT(1)
1000
mhouri.world > select count(1)
2 from (select * from table(f_read_consistency_tab));
COUNT(1)
10
mhouri.world > insert into t_read_consistency
2 (id,vc)
3 select id,vc
4 from table(f_read_consistency_tab)
5 ;
10 rows created.
mhouri.world > select count(1) from t_read_consistency;
COUNT(1)
1010
_11g where the same insert/select is throwing an error:_
mohamed@mhouri> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
mohamed@mhouri> create type t_read_cs as object (id number,vc varchar2(15));
2 /
Type created.
mohamed@mhouri> create type t_read_cs_tab as table of t_read_cs;
2 /
Type created.
mohamed@mhouri> create or replace function f_read_consistency_tab
2 return t_read_cs_tab
3 as
4 lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
5 j binary_integer := 0;
6 begin
7 for x in (select
8 id,
9 vc
10 from t_read_consistency trs
11 where trs.id <= 10
12 ) loop
13
14 j := j +1;
15 lc_t_read_cs_tab.extend;
16 lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
17 end loop;
18 RETURN lc_t_read_cs_tab;
19 end f_read_consistency_tab;
20 /
Function created.
mohamed@mhouri> select count(1) from t_read_consistency;
COUNT(1)
1000
mohamed@mhouri> select count(1) from (select * from table(f_read_consistency_tab));
COUNT(1)
10
mohamed@mhouri> insert into t_read_consistency
2 (id,vc)
3 select id,vc
4 from table(f_read_consistency_tab)
5 ;
from table(f_read_consistency_tab)
ERROR at line 4:
ORA-04091: table MOHAMED.T_READ_CONSISTENCY is mutating, trigger/function may
not see it
ORA-06512: at "MOHAMED.F_READ_CONSISTENCY_TAB", line 7 In addition, one of the posters spotted out very judiciously that if we slightly change the definition of the table t_read_consistency in 11g, strangely the insert/select will work correctly in this data base as shown below:
ohamed@mhouri> drop table tr_read_consistency;
Table dropped.
mohamed@mhouri> create table tr_read_consistency
2 as select rownum rn,
3 trs.*
4 from
5 t_read_consistency trs;
Table created.
mohamed@mhouri> insert into tr_read_consistency
2 (rn, id,vc)
3 select rownum, id,vc
4 from table(f_read_consistency_tab);
10 rows created.So is this a regression? or a corrected bug during upgrade?
Thanks in advance
Mohamed HouriI just followed the doc links provided by Tubby, which have 100% Correct answer. See below :
SQL> select * from v$version;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> show user;
USER is "SCOTT"
SQL> create type t_read_cs as object (id number,vc varchar2(15));
2 /
Type created.
SQL> create type t_read_cs_tab as table of t_read_cs;
2 /
Type created.
SQL> create table t_read_consistency (id number, vc varchar2(15), primary key (id));
Table created.
SQL> create or replace function f_read_consistency_tab
2 return t_read_cs_tab
3 as
4 lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
5 j binary_integer := 0;
6 begin
7 for x in (select
8 id,
9 vc
10 from t_read_consistency trs
11 where trs.id <= 10
12 ) loop
13 j := j +1;
14 lc_t_read_cs_tab.extend;
15 lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
16 end loop;
17 RETURN lc_t_read_cs_tab;
18 end f_read_consistency_tab;
19 /
Function created.
SQL> insert into
2 t_read_consistency
3 select
4 rownum id,
5 rpad('a',15,'a')
6 from
7 dual
8 connect by
9 level<=1000;
1000 rows created.
SQL> select count(1) from t_read_consistency;
COUNT(1)
1000
SQL> select count(1) from (select * from table(f_read_consistency_tab));
COUNT(1)
10
SQL> insert into t_read_consistency
2 (id,vc)
3 select id,vc
4 from table(f_read_consistency_tab);
from table(f_read_consistency_tab)
ERROR at line 4:
ORA-04091: table SCOTT.T_READ_CONSISTENCY is mutating, trigger/function may not see it
ORA-06512: at "SCOTT.F_READ_CONSISTENCY_TAB", line 7
SQL> ed
Wrote file afiedt.buf
1 create or replace function f_read_consistency_tab
2 return t_read_cs_tab
3 as
4 lc_t_read_cs_tab t_read_cs_tab := t_read_cs_tab();
5 j binary_integer := 0;
6 PRAGMA AUTONOMOUS_TRANSACTION; <--- This works as documented in 11.2.0.1
7 begin
8 for x in (select
9 id,
10 vc
11 from t_read_consistency trs
12 where trs.id <= 10
13 ) loop
14 j := j +1;
15 lc_t_read_cs_tab.extend;
16 lc_t_read_cs_tab(j) := t_read_cs(x.id, x.vc);
17 end loop;
18 RETURN lc_t_read_cs_tab;
19* end f_read_consistency_tab;
SQL> /
Function created.
SQL> insert into t_read_consistency
2 (id,vc)
3 select id,vc
4 from table(f_read_consistency_tab);
insert into t_read_consistency
ERROR at line 1:
ORA-00001: unique constraint (SCOTT.SYS_C0011307) violated
SQL> drop table t_read_consistency purge;
Table dropped.
SQL> create table t_read_consistency (id number, vc varchar2(15));
Table created.
SQL> insert into
2 t_read_consistency
3 select
4 rownum id,
5 rpad('a',15,'a')
6 from
7 dual
8 connect by
9 level<=1000;
1000 rows created.
SQL> commit;
Commit complete.
SQL> insert into t_read_consistency
2 (id,vc)
3 select id,vc
4 from table(f_read_consistency_tab);
10 rows created.
SQL> commit;
Commit complete.
SQL>So, you have to add only PRAGMA AUTONOMOUS_TRANSACTION; before begin in your function code to avoid ORA-04091 in 11.2.0.1
But, All thanks to Tubby who pointed us to the correct documentation link.
Regards
Girish Sharma
Maybe you are looking for
-
I have icloud and a new iPhone5 ! They work good , took pictures and a few short movies, plugged in my phone to my iMac transfered Items to iPhoto then inported items to iMovie. when getting to know what i was doing i decided to delete pictures and m
-
We have our Apache install setup with mod_ntlm - this is working fine. I've also followed various notes on these forums and have the authentication scheme setup to use a page sentry function. This is working in the sense that users are authenticated,
-
My iPod always displays the wrong order of songs for particular albums. I tried connecting it to the computer and changing the song order via iTunes but it was correct on iTunes. Went back to iPod and it is still the wrong song order on those albums.
-
Lots of errors 106 MSExchange Common
I get lots of errors 106 MSExchange Common. Details: Performance counter updating error. After that there is a list of running processes displayed. And after that for each process: A process is holding onto a transport performance counter. processId
-
Uverse is blocking my outgoing email
I need to have port 26 opened for my small business in order to send outbound emails.