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 > declaring cursor in Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-21-03, 18:45
Xun_Zhang Xun_Zhang is offline
Registered User
 
Join Date: Nov 2003
Posts: 16
declaring cursor in Function

Briefly said, I want to know whether "declaring cursor in Function" is supported or not. (There is a thread concluding "declaring cursor in trigger" is not supported. )

I am working on porting a cache system from Oracle to DB2, in oracle, we have created triggers that:
1. get a whole list of active nodes from a node management table
2. for each node,
2.1 send an message noticing the change of data.
2.2 wait for acknowledge message returned by the application running on the node.
2.3 if failed, signal error so that change is prevented.

For implementation, we
1. created a Function F1 written in Java for 2.1 and 2.2
2. created a Stored Procedure SP2 which get the node list via a select cursor, then in a loop, calling F1 for each node.
3. create trigger that call SP2.

Since for DB2, trigger can not call store procedure. I will use Function instead. A trigger call Function F2, which get the node list and in turn call the Java Function F1 to send messages.

My question arise when I code F2, I need to use cursor.

If using cursor is supported within a Function, that will be fine. Or discussing workaround will also be very helpful.
Reply With Quote
  #2 (permalink)  
Old 12-09-03, 16:18
dmmac dmmac is offline
Registered User
 
Join Date: Aug 2003
Location: Massachusetts, USA
Posts: 106
Re: declaring cursor in Function

I've used FOR as a way of processing a row at a time from a select, below is the template (but also refer to DB2 manuals on-line):

FOR c1 AS
SELECT ......
DO
call function
some other processing
END FOR;


Quote:
Originally posted by Xun_Zhang
Briefly said, I want to know whether "declaring cursor in Function" is supported or not. (There is a thread concluding "declaring cursor in trigger" is not supported. )

I am working on porting a cache system from Oracle to DB2, in oracle, we have created triggers that:
1. get a whole list of active nodes from a node management table
2. for each node,
2.1 send an message noticing the change of data.
2.2 wait for acknowledge message returned by the application running on the node.
2.3 if failed, signal error so that change is prevented.

For implementation, we
1. created a Function F1 written in Java for 2.1 and 2.2
2. created a Stored Procedure SP2 which get the node list via a select cursor, then in a loop, calling F1 for each node.
3. create trigger that call SP2.

Since for DB2, trigger can not call store procedure. I will use Function instead. A trigger call Function F2, which get the node list and in turn call the Java Function F1 to send messages.

My question arise when I code F2, I need to use cursor.

If using cursor is supported within a Function, that will be fine. Or discussing workaround will also be very helpful.
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