473,386 Members | 1,758 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,386 software developers and data experts.

Before Trigger and UDFs (table)

Hello

Environment: DB2 V8 LUW FP12.

I have a function that returns a table. I am trying to use it inside a
before trigger:
create trigger TRG.T_MACHINE_RTM
before insert on CAD.TBL_MACHINE
REFERENCING NEW as N
for EACH ROW
begin ATOMIC

insert into CAD.T_MACHINE_RTMDB select * from
TABLE(AFU.TABLE_DB_MID('x')) as A;

end@

When I run this I get the following error:

SQL0797N The trigger "TRG.T_MACHINE_RTM" is defined with an
unsupported
triggered SQL statement. LINE NUMBER=10. SQLSTATE=42987

I have also tried a variation: I converted the function to return a
VARCHAR, and changed my insert statement to use VALUES (x,y,
AFU.function). But I also got the same error.

Is there any way to make this work?

Thanks in advance,

Michel

Sep 1 '06 #1
3 3452
I got it to work. Seems like I canīt user before triggers.

Thanks,

Michel Esber escreveu:
Hello

Environment: DB2 V8 LUW FP12.

I have a function that returns a table. I am trying to use it inside a
before trigger:
create trigger TRG.T_MACHINE_RTM
before insert on CAD.TBL_MACHINE
REFERENCING NEW as N
for EACH ROW
begin ATOMIC

insert into CAD.T_MACHINE_RTMDB select * from
TABLE(AFU.TABLE_DB_MID('x')) as A;

end@

When I run this I get the following error:

SQL0797N The trigger "TRG.T_MACHINE_RTM" is defined with an
unsupported
triggered SQL statement. LINE NUMBER=10. SQLSTATE=42987

I have also tried a variation: I converted the function to return a
VARCHAR, and changed my insert statement to use VALUES (x,y,
AFU.function). But I also got the same error.

Is there any way to make this work?

Thanks in advance,

Michel
Sep 1 '06 #2
Michel Esber wrote:
Hello

Environment: DB2 V8 LUW FP12.

I have a function that returns a table. I am trying to use it inside a
before trigger:
create trigger TRG.T_MACHINE_RTM
before insert on CAD.TBL_MACHINE
REFERENCING NEW as N
for EACH ROW
begin ATOMIC

insert into CAD.T_MACHINE_RTMDB select * from
TABLE(AFU.TABLE_DB_MID('x')) as A;

end@
The table function is fine. As long as that function is defined as CONTAINS
or READS SQL DATA (the default), you can use it in a before trigger. But
the problem is in the INSERT. The long explanation of the SQL0797 error
message says:

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
Is there any way to make this work?
Use an AFTER INSERT trigger instead.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 1 '06 #3
Michel Esber wrote:
>
Hello

Environment: DB2 V8 LUW FP12.

I have a function that returns a table. I am trying to use it inside a
before trigger:
create trigger TRG.T_MACHINE_RTM
before insert on CAD.TBL_MACHINE
REFERENCING NEW as N
for EACH ROW
begin ATOMIC

insert into CAD.T_MACHINE_RTMDB select * from
TABLE(AFU.TABLE_DB_MID('x')) as A;

end@

The table function is fine. As long as that function is defined as CONTAINS
or READS SQL DATA (the default), you can use it in a before trigger. But
the problem is in the INSERT. The long explanation of the SQL0797 error
message says:

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
Is there any way to make this work?

Use an AFTER INSERT trigger instead.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany


Thanks Knut. It is working fine now.

Sep 4 '06 #4

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

Similar topics

4
by: DTB | last post by:
I am having trouble creating an INSTEAD OF trigger in SQL Server to replicate a BEFORE UPDATE trigger from ORACLE. Here is a sample of the ORACLE BEFORE UPDATE trigger: CREATE TRIGGER myTRIGGER ON...
3
by: Andrew Mayo | last post by:
There is something very strange going on here. Tested with ADO 2.7 and MSDE/2000. At first, things look quite sensible. You have a simple SQL query, let's say select * from mytab where col1 =...
1
by: Simon Holmes | last post by:
Hi, I am having trouble calling a UDF from a 'before update' trigger whereas I have no problems calling it from the 'after update' trigger. The trigger is as below : CREATE TRIGGER foo NO...
9
by: Raquel | last post by:
Following is a simple trigger definition: CREATE TRIGGER TRIG_EMPLOYEE_1 AFTER UPDATE OF SALARY ON DB2ADMIN.EMPLOYEE FOR EACH STATEMENT MODE DB2SQL CALL DB2ADMIN.SQLSP10( ) This gives an...
3
by: uninfmx | last post by:
Hi If one or mode records get deleted from t1 (see below), I'd like delete all the corresponding records from t2. There is no foreign key relationship between t2 and t1, so cascading delete is...
7
by: Rhino | last post by:
I am updating some Java UDFs from DB2GENERAL to DB2JAVA as suggested in the manuals for DB2 Version 8 but I'm having problems with setSQLstate() and setSQLmessage(). If I'm reading the manuals...
2
by: 73blazer | last post by:
Perhaps my thinking is wrong but this is what I have: 1 table (Tab1) with 1 attribute (Attr1) Attr1 char(16) for bit data ----------------------------------------------- create trigger...
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...
1
by: gauravupreti | last post by:
Hi All, I have a table with a col. that accepts number. CREATE TABLE A (ID NUMBER NOT NULL) and another table with two columns as shown: CREATE TABLE B (ID NUMBER NOT NULL,
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.