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 to call one procedure from another procedure in a select block.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-15-09, 10:38
avishalpatil avishalpatil is offline
Registered User
 
Join Date: May 2009
Posts: 12
Red face How to call one procedure from another procedure in a select block.

Hi all,
How to call one procedure from another procedure in a select block?
Here is the code for reference

CREATE PROCEDURE PROC1 (IN i_perinc VARCHAR(2),OUT result float)
LANGUAGE SQL
Begin
declare cost float;
DECLARE c1 CURSOR WITH RETURN FOR
SELECT product_id,item_cost cost1 FROM product where product_id = i_perinc;
SET cost = cost1;
OPEN c1;
END


Now I am trying to call this SP from another SP given below:

CREATE PROCEDURE PROC2 ( IN Name CHAR(4) )
LANGUAGE SQL
DYNAMIC RESULT SETS 1
P1: BEGIN
-- Declare cursor
Declare v1 VARCHAR(2);
DECLARE cursor1 CURSOR FOR
SELECT
AIRPORT_CODE,
call PROC1(AIRPORT.i_perinc)
FROM AIRPORT AS AIRPORT WHERE AIRPORT.AIRPORT_CODE = Name;
OPEN cursor1;
fetch cursor1 into v1;
END P1


Regards
Vishal
Reply With Quote
  #2 (permalink)  
Old 05-15-09, 11:19
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Which DB2 version and OS?

Andy
Reply With Quote
  #3 (permalink)  
Old 05-15-09, 11:30
avishalpatil avishalpatil is offline
Registered User
 
Join Date: May 2009
Posts: 12
DB2 Version 9.2
Operating System Windows 2003


Regards
Vishal
Reply With Quote
  #4 (permalink)  
Old 05-15-09, 11:39
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You need to look at the ASSOCIATE LOCATORS and the ALLOCATE CURSOR statements.

IBM DB2 9.5 Information Center for Linux, UNIX, and Windows

IBM DB2 9.5 Information Center for Linux, UNIX, and Windows

Andy
Reply With Quote
  #5 (permalink)  
Old 05-15-09, 16:16
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
CALL is a SQL statement on its own. It cannot be used as part of some other SQL statement like a SELECT statement.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
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