Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Dynamic sql statement called in a stored procedure SP

 
   Database Help (Home) -> DB2 RSS
Next:  Hidden Form Unhiding  
Author Message
Justin

External


Since: Feb 07, 2008
Posts: 15



(Msg. 1) Posted: Fri Oct 03, 2008 8:38 am
Post subject: Dynamic sql statement called in a stored procedure SP
Archived from groups: comp>databases>ibm-db2 (more info?)

We have a stored procedure that dynamically builds a sql statement.

Is there an example of how to get the SP to return the result set of a
dynamically generated sql statement.

here is an oversimplified sql statement - just to prove the point:

set SQLStatement = 'select c1, c2 from syscat.tables ';
set SQLStatement = SQLStatement || 'where other stuff...'
set SQLStatement = SQLStatement || 'UNION select A2, B3 from X where
other stuff...'


--execute immediate SQLStatement;--
PREPARE stmt1 from SQLStatement;
EXECUTE stmt1;

 >> Stay informed about: Dynamic sql statement called in a stored procedure SP 
Back to top
Login to vote
jefftyzzer

External


Since: Jan 14, 2008
Posts: 65



(Msg. 2) Posted: Fri Oct 03, 2008 11:31 am
Post subject: Re: Dynamic sql statement called in a stored procedure SP [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Oct 3, 8:38 am, Justin <kfw....RemoveThis@hotmail.com> wrote:
> We have a stored procedure that dynamically builds a sql statement.
>
> Is there an example of how to get the SP to return the result set of a
> dynamically generated sql statement.
>
> here is an oversimplified sql statement - just to prove the point:
>
> set SQLStatement = 'select c1, c2 from syscat.tables ';
> set SQLStatement = SQLStatement ||  'where other stuff...'
> set SQLStatement = SQLStatement ||  'UNION select A2, B3 from X where
> other stuff...'
>
> --execute immediate SQLStatement;--
> PREPARE stmt1 from SQLStatement;
> EXECUTE stmt1;

CREATE PROCEDURE RET_TEST()
LANGUAGE SQL
SPECIFIC ARCHIVE_RET_TEST
INHERIT SPECIAL REGISTERS
DYNAMIC RESULT SETS 1
BEGIN
DECLARE V_RETURN CHAR(30);--

DECLARE C_RETURN CURSOR WITH RETURN FOR S_RETURN;--

-- Build statement here
SET V_RETURN = 'SELECT * FROM SYSIBM.SYSDUMMY1';--

PREPARE S_RETURN FROM V_RETURN;--

OPEN C_RETURN;--
END;


--Jeff

 >> Stay informed about: Dynamic sql statement called in a stored procedure SP 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
stored procedure or SELECT statement - Hi, I'm trying to find the most efficient way to access DB2 data on z/OS DB2 V8. Any suggestions would be welcomed . . . Situation: 1. Converting a VSAM file to DB2 on z/OS 2. VSAM file will be populated into 4 DB2 tables, 1 parent and 3 child table...

z/OS DB2 SPUFI called procedure - Can you use SPUFI to call a procedure in z/OS DB2? Regards, Serenity

DB2 COBOL stored procedure to UDB SQL stored procedure - I have been given the task of taking a 3,200 line COBOL stored procedure and duplicating the same functionality in UDB 7.2 on the Windows platform with a procedural SQL stored procedure. I have fiddled with procedural SQL stored procs on UDB, but mostly...

Dynamic statement cache on LUW - DB2 LUW 8.1 fixpak 14 Red Hat EL AS 4.4 I'm trying to diagnose some nocturnal CPU pressure, and am trying to understand the dynamic statement cache as it applies to LUW. The only doc/redbooks I am finding are for Z/OS, which I am completely ignorant of...

Need help with Stored Procedure - Chris Eaton gave an example of stored procedure transpose columns to rows Here is an example of a rowtocol stored proc that takes a SQL statement as the first paramter, a delimiter as the second parameter and the ouput (in the 3rd parameter) is the rows....
   Database Help (Home) -> DB2 All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]