Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old September 2nd, 2008, 10:45 PM
Mark A
Guest
 
Posts: n/a
Default Re: select in a stored procedure call

"Serge Rielau" <srielau@ca.ibm.comwrote in message
news:6i5c4rFoto1gU1@mid.individual.net...
Quote:
You need to a put the selEct into a cursor WITH RETURN TO CLIENT
>
DECLARE ....;
DECLARE result CURSOR WITH RETURN TO CLIENT AS SELECT .....;
>
SET v_search....;
OPEN result;
END
>
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
When are we getting the execute immediate for "select ... into..." that you
mentioned about 3 years ago?





  #2  
Old September 2nd, 2008, 11:35 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: select in a stored procedure call

Mark A wrote:
Quote:
"Serge Rielau" <srielau@ca.ibm.comwrote in message
news:6i5c4rFoto1gU1@mid.individual.net...
Quote:
>You need to a put the selEct into a cursor WITH RETURN TO CLIENT
>>
>DECLARE ....;
>DECLARE result CURSOR WITH RETURN TO CLIENT AS SELECT .....;
>>
>SET v_search....;
>OPEN result;
>END
>>
>--
>Serge Rielau
>DB2 Solutions Development
>IBM Toronto Lab
>
When are we getting the execute immediate for "select ... into..." that you
mentioned about 3 years ago?
DB2 9.5 introduced dynamic SET statement. Same thing. Just better.
SET (?, ...?) = (SELECT .....)

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #3  
Old September 2nd, 2008, 11:35 PM
Mark A
Guest
 
Posts: n/a
Default Re: select in a stored procedure call

"Serge Rielau" <srielau@ca.ibm.comwrote in message
news:6i5su7Fp0n6nU1@mid.individual.net...
Quote:
DB2 9.5 introduced dynamic SET statement. Same thing. Just better.
SET (?, ...?) = (SELECT .....)
>
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Just to make sure I am understanding this correctly, I need the select to be
dynamic since the table and column names change. Can the right half be a
variable?


  #4  
Old September 3rd, 2008, 12:45 AM
Serge Rielau
Guest
 
Posts: n/a
Default Re: select in a stored procedure call

Mark A wrote:
Quote:
"Serge Rielau" <srielau@ca.ibm.comwrote in message
news:6i5su7Fp0n6nU1@mid.individual.net...
Quote:
>DB2 9.5 introduced dynamic SET statement. Same thing. Just better.
>SET (?, ...?) = (SELECT .....)
>>
>Cheers
>Serge
>--
>Serge Rielau
>DB2 Solutions Development
>IBM Toronto Lab
>
Just to make sure I am understanding this correctly, I need the select to be
dynamic since the table and column names change. Can the right half be a
variable?
CREATE PROCEDURE p(IN pin INTEGER, OUT pout INTEGER)
BEGIN
DECLARE txt VARCHAR(2000);
DECLARE stmt STATEMENT;
SET txt = 'SET ? = (SELECT ? + 1 FROM SYSIBM.SYSDUMMY1)';
PREPARE stmt FROM txt;
EXECUTE stmt INTO pout USING pin;
END
@

db2 =call p(6, ?)@

Value of output parameters
--------------------------
Parameter Name : POUT
Parameter Value : 7

Return Status = 0


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #5  
Old September 4th, 2008, 03:25 PM
Serge Rielau
Guest
 
Posts: n/a
Default Re: select in a stored procedure call

Justin,

Where did you find that syntax? And double quotes for a string?
You need to declare the cursor on a STATEMENT type variable
Quote:
Quote:
>>-DECLARE--cursor-name--CURSOR--●--| holdability |--●---------->
Quote:
>--| returnability |--●--FOR--+-select-statement-+-------------><
'-statement-name---' <-- You are here


So you do:

DECLARE txt VARCHAR(1000);
DECLARE stmt STATEMENT;
DECLARE cur CURSOR WITH RETURN TO CLIENT FOR stmt;

SET txt = 'SELECT ....';
PREPARE stmt FROM txt;
OPEN cur;


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
  #6  
Old September 4th, 2008, 04:05 PM
Justin
Guest
 
Posts: n/a
Default Re: select in a stored procedure call


Serge,

I am impressed with your quick response. The double quotes / syntax
were attempts on my part to try various options.

But - the last suggestion worked.

Thank you very much.

-JB



On Sep 4, 10:20 am, Serge Rielau <srie...@ca.ibm.comwrote:
Quote:
Justin,
>
Where did you find that syntax? And double quotes for a string?
You need to declare the cursor on a STATEMENT type variable
Quote:
Quote:
>>-DECLARE--cursor-name--CURSOR--$B!|(B--| holdability |--$B!|(B---------->
>
Quote:
>--| returnability |--$B!|(B--FOR--+-select-statement-+-------------><
'-statement-name---' <-- You are here
>
So you do:
>
DECLARE txt VARCHAR(1000);
DECLARE stmt STATEMENT;
DECLARE cur CURSOR WITH RETURN TO CLIENT FOR stmt;
>
SET txt = 'SELECT ....';
PREPARE stmt FROM txt;
OPEN cur;
>
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.