473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mutating tables

Hello -

I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table errors if you either need
access to the :old or the :new values within a trigger. But what if
you need access to both? Or is this even possible (I'm fairly new to
triggers).

I have to execute a select count(*) from trigger_table where
value1=:old.val ue1 and value2=:old.val ue2. Based on this result, log
files must be written utilizing the :new values. A simplified example
of my trigger is below:

CREATE OR REPLACE TRIGGER mut_trigger
AFTER INSERT OR UPDATE OF value1, value2
ON table_a
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
numofdocs number;
BEGIN
select count(*) into numofdocs from table_a where value1=:old.val ue1
and value2=:old.val ue2;
if (numofdocs > 0) then
insert into log_table1 values ('Log data', :new.value1,
:new.value2);
insert into log_table2 values ('Log data', :new.value1,
:new.value2);
end if;
END;

Is there any way to get what I need using one trigger?

Thanks so much,
Melissa
Jul 19 '05 #1
4 7047
Simply placing the select statement in a statement level trigger instead in
a row level trigger gives the solution. In addition, you need to store the
old en new values in something like a packaged pl/sql table, which you can
acces in the statement level trigger. Filling the pl/sql table occurs in the
row level trigger. Besides, the query is a little bit useless when
inserting, since in that case old values simply don't exists, i.e. equals
null (numofdocs whill alwasy equal 0 when inserting).
"M Mueller" <me************ *@yahoo.com> schrieb im Newsbeitrag
news:ac******** *************** ***@posting.goo gle.com...
Hello -

I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table errors if you either need
access to the :old or the :new values within a trigger. But what if
you need access to both? Or is this even possible (I'm fairly new to
triggers).

I have to execute a select count(*) from trigger_table where
value1=:old.val ue1 and value2=:old.val ue2. Based on this result, log
files must be written utilizing the :new values. A simplified example
of my trigger is below:

CREATE OR REPLACE TRIGGER mut_trigger
AFTER INSERT OR UPDATE OF value1, value2
ON table_a
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
numofdocs number;
BEGIN
select count(*) into numofdocs from table_a where value1=:old.val ue1
and value2=:old.val ue2;
if (numofdocs > 0) then
insert into log_table1 values ('Log data', :new.value1,
:new.value2);
insert into log_table2 values ('Log data', :new.value1,
:new.value2);
end if;
END;

Is there any way to get what I need using one trigger?

Thanks so much,
Melissa

Jul 19 '05 #2
Simply placing the select statement in a statement level trigger instead in
a row level trigger gives the solution. In addition, you need to store the
old en new values in something like a packaged pl/sql table, which you can
acces in the statement level trigger. Filling the pl/sql table occurs in the
row level trigger. Besides, the query is a little bit useless when
inserting, since in that case old values simply don't exists, i.e. equals
null (numofdocs whill alwasy equal 0 when inserting).
"M Mueller" <me************ *@yahoo.com> schrieb im Newsbeitrag
news:ac******** *************** ***@posting.goo gle.com...
Hello -

I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table errors if you either need
access to the :old or the :new values within a trigger. But what if
you need access to both? Or is this even possible (I'm fairly new to
triggers).

I have to execute a select count(*) from trigger_table where
value1=:old.val ue1 and value2=:old.val ue2. Based on this result, log
files must be written utilizing the :new values. A simplified example
of my trigger is below:

CREATE OR REPLACE TRIGGER mut_trigger
AFTER INSERT OR UPDATE OF value1, value2
ON table_a
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
numofdocs number;
BEGIN
select count(*) into numofdocs from table_a where value1=:old.val ue1
and value2=:old.val ue2;
if (numofdocs > 0) then
insert into log_table1 values ('Log data', :new.value1,
:new.value2);
insert into log_table2 values ('Log data', :new.value1,
:new.value2);
end if;
END;

Is there any way to get what I need using one trigger?

Thanks so much,
Melissa

Jul 19 '05 #3
Simply placing the select statement in a statement level trigger instead in
a row level trigger gives the solution. In addition, you need to store the
old en new values in something like a packaged pl/sql table, which you can
acces in the statement level trigger. Filling the pl/sql table occurs in the
row level trigger. Besides, the query is a little bit useless when
inserting, since in that case old values simply don't exists, i.e. equals
null (numofdocs whill alwasy equal 0 when inserting).
"M Mueller" <me************ *@yahoo.com> schrieb im Newsbeitrag
news:ac******** *************** ***@posting.goo gle.com...
Hello -

I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table errors if you either need
access to the :old or the :new values within a trigger. But what if
you need access to both? Or is this even possible (I'm fairly new to
triggers).

I have to execute a select count(*) from trigger_table where
value1=:old.val ue1 and value2=:old.val ue2. Based on this result, log
files must be written utilizing the :new values. A simplified example
of my trigger is below:

CREATE OR REPLACE TRIGGER mut_trigger
AFTER INSERT OR UPDATE OF value1, value2
ON table_a
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
numofdocs number;
BEGIN
select count(*) into numofdocs from table_a where value1=:old.val ue1
and value2=:old.val ue2;
if (numofdocs > 0) then
insert into log_table1 values ('Log data', :new.value1,
:new.value2);
insert into log_table2 values ('Log data', :new.value1,
:new.value2);
end if;
END;

Is there any way to get what I need using one trigger?

Thanks so much,
Melissa

Jul 19 '05 #4
@#$$#%^%%&^
"M Mueller" <me************ *@yahoo.com> wrote in message
news:ac******** *************** ***@posting.goo gle.com...
Hello -

I'm using Oracle 8i and am running into the infamous mutating table
error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen
examples for getting around mutating table errors if you either need
access to the :old or the :new values within a trigger. But what if
you need access to both? Or is this even possible (I'm fairly new to
triggers).

I have to execute a select count(*) from trigger_table where
value1=:old.val ue1 and value2=:old.val ue2. Based on this result, log
files must be written utilizing the :new values. A simplified example
of my trigger is below:

CREATE OR REPLACE TRIGGER mut_trigger
AFTER INSERT OR UPDATE OF value1, value2
ON table_a
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
DECLARE
numofdocs number;
BEGIN
select count(*) into numofdocs from table_a where value1=:old.val ue1
and value2=:old.val ue2;
if (numofdocs > 0) then
insert into log_table1 values ('Log data', :new.value1,
:new.value2);
insert into log_table2 values ('Log data', :new.value1,
:new.value2);
end if;
END;

Is there any way to get what I need using one trigger?

Thanks so much,
Melissa

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4275
by: Joel Jose | last post by:
agreed the 'mutation engine' by dark avenger was a real deadly master-code piece.., but then.. if one could create a self mutating code..in real time then i think it would just b the most technical advancement of this century!!! just think... instead of those nagging.. and more irritating than helpfull death screen(error logs).. that windows shows every other time.. if it could evolve itself to cope up with the error.. if the pe...
2
4714
by: robert | last post by:
i've found the solution threads on changing a column on insert. works fine. question: - will one package serve for all such triggers, or does there need to be a package defined to support each table? my o'reilly book doesn't say, nor do the threads i found.
4
7461
by: M | last post by:
Hello, I have a very simple table, and want to create a trigger that updates the date column entry (with the current date), whenever a row gets modified. Is there a simple way of fixing this, or would I have to create 3 extra triggers, a package, etc., as described in most posts about mutating table errors? Could you please explain to me WHY this error happens here (I have not been able to find a clear explanation of what causes them)?
0
2145
by: hankr | last post by:
I have only a developer's level knowledge of Oracle, though I have access to DBA tools. Searches through the docs have not been fruitful, so I thought I'd try here. I am getting an error on a simple 1-row I-SQL delete statement that a different table may be "mutating" and the transaction is then rolled-back. I understand what this means, and have fixed "mutating" errors before. But I cannot for the life of me trace-thru in the...
0
1542
by: AYAN MUKHERJEE | last post by:
I have 2 tables. 1) emp_test, 2) newemp_test. I had created a trigger to insert automatic data in the table no. 2 , as soon as a row of information is inserted in table no. 1. The Trigger had been successfully done, but as I try to insert a row in the table after running the Trigger this error is getting generated. ************************************************************************************** SQL> insert into emp_test (empno, empname,...
3
3704
by: extremexpert | last post by:
Hai all, I have two tables like hdr and det. I would like to create the trigger for the situation ' 1.Delete Det table records, if any record is deleting in hdr table 2. Delte hdr table records, if any record is deleting in det table '. I have created the trigger for both the tables, but i am facing ' Mutating Error'.... Any suggestions please
4
175
by: M Mueller | last post by:
Hello - I'm using Oracle 8i and am running into the infamous mutating table error on an AFTER INSERT OR UPDATE FOR EACH ROW trigger. I have seen examples for getting around mutating table errors if you either need access to the :old or the :new values within a trigger. But what if you need access to both? Or is this even possible (I'm fairly new to triggers). I have to execute a select count(*) from trigger_table where
1
3413
by: gangulajagan | last post by:
Could any one please explain me what is a Mutating Table Or Mutaing Trigger and how to overcome it? Are both Mutating trigger and Mutating Table one and same? Please Explain me with an example if possible. Thanks in advance.
16
7028
by: vamsioracle | last post by:
Can Someone help me how to avoid mutating error while using triggers. I work on oracle apps. I created a vacation rule such that responsibility is delegated to other person. These details are captured in wf_routing_rules. I created a procedure that takes the values from wf_routing_rules and sends mail using utl_smtp. I created a trigger such that for every row insert in wf_routing_rules, this procedure is called. I know that doing a...
0
8139
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7024
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.