473,414 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Trigger fails when stored procedure is called two times in a row

I am puzzled by the following behavior.
If stored procedure PROC1 is called 2 times in trigger TRIG1, then I
get error during trigger firing:

SQL0723N An error occurred in a triggered SQL statement in trigger
"DB2ADMIN.TRIG1". Information returned for the error includes SQLCODE
"-746", SQLSTATE "57053" and message tokens
"DB2ADMIN.PROC1|SQL051130081021635|TRIG". SQLSTATE=09000
CREATE TRIGGER TRIG1 AFTER UPDATE OF USER ON TABLE1
REFERENCING NEW AS TriggeredRow
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
CALL DB2ADMIN.PROC1(TriggeredRow.ID, TriggeredRow.USER, 'Situation 1');
CALL DB2ADMIN.PROC1(TriggeredRow.ID, TriggeredRow.USER, 'Situation
2');
END
$

PROC1 is SQL stored procedure that inserts records into TABLE2.
If I call PROC1 just once in TRIG1, then it works fine. Why?

Dec 1 '05 #1
6 5898
db2 => ? sql-746
SQL0746N Routine "<routine-name>" (specific name
"<specific-name>") violated nested SQL statement rules
when attempting to perform operation "<operation>" on
table "<table-name>".

Explanation:

The routine "<routine-name>" (specific name
"<specific-name>") attempted to perform the operation
"<operation>" on table "<table-name>". This operation conflicts
with other uses of the table by either the application, or a
routine invoked directly or indirectly from that application.

If the operation is "READ", then the table "<table-name>" is
currently being written to by either the application or another
routine.

If the operation is "MODIFY", then the table "<table-name>" is
already being read from or written to by the application or another
routine.

If "<table-name>" references an explain table and the statement
that receives this error message is either a PREPARE statement or
an EXECUTE IMMEDIATE statement, then a conflict occurred when
inserting explain information into the explain table.

User Response:

The operation may be successful if retried. Redesign either the
application or the routine to avoid the conflict.

If the conflict occurred when inserting explain information for
a dynamic statement, then disable explain for dynamic statements
and try the PREPARE statement or EXECUTE IMMEDIATE statement
again.

sqlcode : -746

sqlstate : 57053

---

It sounds to me as the two operations cannot both be done at the same
time.

B.

Dec 1 '05 #2
But why?

Dec 1 '05 #3
The error message says why.

SQL0746N Routine "<routine-name>" (specific name
"<specific-name>") violated nested SQL statement rules
when attempting to perform operation "<operation>" on
table "<table-name>".

So you have that error message (with the variables filled in)?

Dec 1 '05 #4
Antanas wrote:
I am puzzled by the following behavior.
If stored procedure PROC1 is called 2 times in trigger TRIG1, then I
get error during trigger firing:

SQL0723N An error occurred in a triggered SQL statement in trigger
"DB2ADMIN.TRIG1". Information returned for the error includes SQLCODE
"-746", SQLSTATE "57053" and message tokens
"DB2ADMIN.PROC1|SQL051130081021635|TRIG". SQLSTATE=09000
CREATE TRIGGER TRIG1 AFTER UPDATE OF USER ON TABLE1
REFERENCING NEW AS TriggeredRow
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
CALL DB2ADMIN.PROC1(TriggeredRow.ID, TriggeredRow.USER, 'Situation 1');
CALL DB2ADMIN.PROC1(TriggeredRow.ID, TriggeredRow.USER, 'Situation
2');
END
$

PROC1 is SQL stored procedure that inserts records into TABLE2.
If I call PROC1 just once in TRIG1, then it works fine. Why?

This is working as designed see error message for -723.
Its being worked on for a V8 fixpack. Feel free to open a PMR for
further assistance.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Dec 1 '05 #5
Antanas wrote:
But why?

In the SQL Standard AFTER triggers are defined to fire after ALL ros
have been UPDATES/INSERTED/DELETED.
DB2 analyzes the body of the trigger to find out whether it can
streamline the trigger to execute per row as the row gets modified.
Since the CALL statement does not tell which tables are modifyed in teh
stored procedure DB2 flags all changed tables to prevent breakage of the
SQL Standard semantics. If read/wrote or write/write conflict (aka.
mutating table conflict) is detected you get this error.

Turns out this error is encountered more often than anticipated and
development is working on a fix. Feel free to open a PMR.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Dec 1 '05 #6
Thanks, Serge.

Dec 1 '05 #7

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

Similar topics

9
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
1
by: Jen S | last post by:
I feel like I'm missing something obvious here, but I'm stumped... I have a stored procedure with code that looks like: INSERT INTO MyTableA ( ...fields... ) VALUES (...values...) IF...
18
by: Bill Smith | last post by:
The initial row is inserted with the colPartNum column containing a valid LIKE pattern, such as (without the single quotes) 'AB%DE'. I want to update the column value with the results of a query...
4
by: Alexander Pope | last post by:
I am using db2 udb v8.2 AIX I have created trigger, however I am not confident it meets industry standards. If I make it fail, I cant tell from the message where it is failing. what can I add to...
0
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as...
1
by: deepdata | last post by:
Hi, I am creating a trigger in DB2 express version. When i use the following syntax to create trigger CREATE TRIGGER USER_PK_TRIGGER BEFORE INSERT On users REFERENCING NEW As N FOR EACH...
5
by: wpellett | last post by:
I can not get the SQL compiler to rewrite my SQL UPDATE statement to include columns being SET in a Stored Procedure being called from a BEFORE UPDATE trigger. Example: create table...
5
by: marcsirois | last post by:
I am maintaining an application where most of the business rules are in Triggers, Stored Procedures and User Defined Functions. When a bug arises, it can get very tedious to debug. Today for...
3
by: yinzara | last post by:
I have the following trigger that calls a DB2 stored procedure: DROP TRIGGER GGWU.TRI_A_MULTI_PROP@ CREATE TRIGGER GGWU.TRI_A_MULTI_PROP AFTER INSERT ON GGWU.MULTIPLIER_PROPERTY REFERENCING ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.