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 > How DB2 support Multiple value parameters in Stored Procedure?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-05-06, 21:56
kiluyar kiluyar is offline
Registered User
 
Join Date: Aug 2006
Posts: 13
Question How DB2 support Multiple value parameters in Stored Procedure?

Hi, Everybody
I want to write a SP which use a parameter to accept some values once. For example, I want to pass 5 values to this parameter and read them one by one in SP.
I don't know whether DB2 can support this just like Oracle. Oracle has VARRAY and Nested Table to do this. The VARRAY and Nested TAble both can be used as the parameter type in a SP.
Thank you very much!!!
Reply With Quote
  #2 (permalink)  
Old 09-06-06, 05:06
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Use Declared global temp tables

HTH

Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 09-06-06, 05:17
kiluyar kiluyar is offline
Registered User
 
Join Date: Aug 2006
Posts: 13
Can you give me an example? Can I use a table type parameter?
Reply With Quote
  #4 (permalink)  
Old 09-06-06, 06:44
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
Here's an example ...

CREATE PROCEDURE PROCEDURE1 ( )
------------------------------------------------------------------------
-- SQL Stored Procedure
------------------------------------------------------------------------
P1: BEGIN
DECLARE CHAR2 CHAR(100) ;
--- The following GTT declaration and INSERT typically will happen outside of the stored proc.
DECLARE GLOBAL TEMPORARY TABLE SESSION.AMOUNT_GTT(CURRENCY_CD CHAR(3),AMOUNT DECIMAL(10,3)) WITH REPLACE NOT LOGGED ;
INSERT INTO SESSION.AMOUNT_GTT values('USD',100),('GBP',200),('EUR',500) ;
--- The procedure is now called and the rows in the global temp table are used for processing
--- If GTT was defined outside the scope of this stored proc, a dummy definition has to be done in
--- procedure for compilation purposes, as follows
--- if (1=1) then
--- DECLARE GLOBAL TEMPORARY TABLE SESSION.AMOUNT_GTT(CURRENCY_CD CHAR(3),AMOUNT DECIMAL(10,3)) WITH REPLACE NOT LOGGED ;
--- end if ;

BEGIN
declare usd_amt decimal(10,3) ;
FOR PROCESS1 AS SELECT currency_cd,amount FROM SESSION.AMOUNT_GTT -- LOOPS THROUGH THE GTT RECORDS, 1 ROW AT A TIME.
DO
-- DO YOUR PROCESSING HERE
set usd_amt=case CURRENCY_CD
when 'USD' then AMOUNT
when 'GBP' THEN AMOUNT*1.8
WHEN 'EUR' THEN AMOUNT*1.2
EnD ;
END FOR ;
END ;
END P1
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
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