Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / January 2005

Tip: Looking for answers? Try searching our database.

Trigger porting problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gustavo_randich@yahoo.com.ar - 20 Jan 2005 15:38 GMT
Hi :-)

I'm porting a project from Oracle to DB2 and now I'm trying to avoid
error SQL0746N in a trigger which reads the same table in which the
trigger is defined.

Below is Oracle's workaround for this problem (Oracle raises a similar
error when trying to do this). It uses a package to temporarily store
affected rows in a BEFORE trigger for later processing in an AFTER
trigger. Is there a functionality in DB2 similar to Oracle's packages
(sort of arrays

-- SUPPORTING PACKAGE
create or replace package myTable_pkg as
...type rarray is table of rowid index by binary_integer;
...rids rarray;
...type rMyField1 is table of myType1 index by binary_integer;
...myField1 rMyField1;
...type rMyField2 is table of myType2 index by binary_integer;
...myField1 rMyField2;
......
......
...cnt number;
end;

-- INITIALIZE COUNTER BEFORE UPDATE
create or replace trigger myTable_bu before update on myTable
begin
...myTable.cnt := 0;
end;

-- POPULATE ARRAY FOR EACH UPDATED ROW
create or replace trigger myTable_aufer after update on myTable
for each row
begin
...myTable.cnt := myTable.cnt + 1;
...myTable.rids(myTable.cnt) := :new.rowid;
...myTable.myField1(myTable.cnt) := :old.myField1;
...myTable.myField2(myTable.cnt) := :old.myField2;
......
......
end;

-- DO ACTIONS FOR EACH UPDATED ROW AFTER UPDATE
create or replace trigger myTable_au after update on myTable
declare
...myRow myTable%rowtype;
begin
...for i in 1 .. myTable.cnt loop
......select * into myRow from myTable where rowid = myTable.rids(i);
......procWhichReadsMyTable(myRow.myField1, myRow.myField2, ...);
...end loop;
end;
Serge Rielau - 21 Jan 2005 13:56 GMT
> Hi :-)
>
[quoted text clipped - 49 lines]
> ...end loop;
> end;

Gustavo,

Two options:
1. Try to perform the read inside the trigger instead of inside the
procedure. The trigger itself can deal with these conflicts thanks to
inline SQL PL.
2. Open a PMR. You are not alone with this problem (in fact it was
debated in this group mere weeks ago) and DB2 Development is much more
interested in fixing this one for real than teetering along with
workarounds. We clearly underestimated the likelyhood of mutating table
conflicts.
When you open the PMR. Ask support to get touch with me.

Cheers
Serge

Signature

Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

gustavo_randich@yahoo.com.ar - 21 Jan 2005 14:37 GMT
Serge,

Thanks for the response. I'll open a PMR.

-----------------------------------
Lic. Gustavo J. Randich
Tecnología Informática
ARDISON Software & Consulting
www.ardison.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.