If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > help with trigger that calls a stored procedure, win32 v9.5

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-01-09, 19:49
craigmc craigmc is offline
Registered User
 
Join Date: Aug 2003
Location: austin,tx
Posts: 90
help with trigger that calls a stored procedure, win32 v9.5

Can anyone tell me why this create trigger stmt fails? It tells me the trigger is defined with an unsupported triggered sql statement, but I can't figure out why. The docs say a BEFORE trigger can call a stored proc if it doesn't modify sql data. What am I missing?
Thanks!


-- create a test table
CREATE TABLE TMP_TEST (col1 varchar(20))

-- create a simple test stored procedure
DROP PROCEDURE TMP_TEST_SP
CREATE PROCEDURE TMP_TEST_SP ( IN var1 varchar(32) )
P1: BEGIN
SET var1 = 'bar';
END P1

-- test procedure
CALL TMP_TEST_SP ('foo')

-- create a trigger that calls the SP, why doesn't this work?
CREATE TRIGGER TMP_TEST_TRIGGER
BEFORE INSERT ON TMP_TEST
REFERENCING NEW AS inserted
FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
CALL TMP_TEST_SP('foo');
END

-- drop everything
DROP TRIGGER TMP_TEST_TRIGGER
DROP PROCEDURE TMP_TEST_SP
DROP TABLE TMP_TEST



Here is the error:
The trigger "DB2ADMIN.TMP_TEST_TRIGGER" is defined with an unsupported triggered SQL statement.. SQLCODE=-797, SQLSTATE=42987, DRIVER=3.53.71


C:\DB2\REPLWORK>db2 ? sql-797


SQL0797N The trigger "<trigger-name>" is defined with an unsupported
triggered SQL statement.

Explanation:

The trigger must be defined with a triggered SQL statement that can only
include statements from the following list.
* A trigger can include the following control statements:
* dynamic compound statement
* FOR statement
* GET DIAGNOSTICS statement
* IF statement
* ITERATE statement
* LEAVE statement
* SIGNAL statement
* WHILE statement

* A BEFORE trigger can also include the following triggered SQL
statements:
* a CALL statement which invokes a procedure that does not modify
SQL data
* a fullselect
* an assignment statement



However, the triggered SQL statements in a BEFORE trigger cannot
include:
* a table function that modifies SQL data
* a nested DELETE, INSERT, MERGE, or UPDATE statement

* An AFTER trigger can also include the following triggered SQL
statements:
* an INSERT statement
* a searched UPDATE statement
* a searched DELETE statement
* a MERGE statement
* a CALL statement
* a fullselect
* an assignment statement (excluding assignment of transition
variables)

* An INSTEAD OF trigger can also include the following triggered SQL
statements:
* an INSERT statement
* a searched UPDATE statement
* a searched DELETE statement
* a MERGE statement
* a CALL statement
* a fullselect
* an assignment statement (excluding assignment of transition
variables)

In some cases the "<trigger-name>" is not available for use in the
message.

User response:

Check the triggered SQL statements in the trigger for any statement that
does not match the above list and remove it.

sqlcode: -797

sqlstate: 42987
Reply With Quote
  #2 (permalink)  
Old 12-01-09, 20:29
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
If you look at the CREATE PROCEDURE syntax diagram you will notice that the statement defaults to MODIFIES SQL DATA, if that clause is not specified explicitly as something else (e.g. CONTAINS SQL). Procedure declaration is the only way for the compiler to determine whether it modifies data or not.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On