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

Need help with Stored Procedure

 
   Database Help (Home) -> DB2 RSS
Next:  UDB JDBC procedure call causes S04E in DB2  
Author Message
lenygold via DBMonster.co

External


Since: Feb 19, 2008
Posts: 80



(Msg. 1) Posted: Wed Mar 12, 2008 9:11 pm
Post subject: Need help with Stored Procedure
Archived from groups: comp>databases>ibm-db2 (more info?)

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 coverted to a column with the delimiter specified
used to separate the row values:

CREATE PROCEDURE rowtocol
(IN p_slct VARCHAR(4000), IN p_dlmtr VARCHAR(4000), OUT lc_str VARCHAR(4000))
LANGUAGE SQL
BEGIN
DECLARE SQLSTATE CHAR(5);
DECLARE lc_colval VARCHAR(4000);
DECLARE c_refcur INT;
DECLARE at_end INT DEFAULT 0;

DECLARE not_found CONDITION FOR SQLSTATE '02000';

DECLARE C1 CURSOR FOR S1;
DECLARE CONTINUE HANDLER FOR not_found SET at_end = 1;

PREPARE S1 FROM p_slct;

SET lc_str = '';
OPEN C1;
fetch_loop:
LOOP
FETCH C1 INTO lc_colval;
IF at_end = 1 THEN LEAVE fetch_loop;
END IF;
SET lc_str = lc_str || p_dlmtr || lc_colval;
END LOOP;
CLOSE C1;
END

When i try to use it
CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY',',');
i got the following error:
sqlcode: -440
The parameter mode (IN, OUT, or INOUT) is not valid for a parameter in
procedure.

How to fix my call?
Thank's in advance.

--
Message posted via http://www.dbmonster.com

 >> Stay informed about: Need help with Stored Procedure 
Back to top
Login to vote
Mark A2

External


Since: Mar 13, 2004
Posts: 183



(Msg. 2) Posted: Wed Mar 12, 2008 9:11 pm
Post subject: Re: Need help with Stored Procedure [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"lenygold via DBMonster.com" <u41482@uwe> wrote in message
news:810ffe956a9f2@uwe...
> 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 coverted to a column with the delimiter
> specified
> used to separate the row values:
>
> CREATE PROCEDURE rowtocol
> (IN p_slct VARCHAR(4000), IN p_dlmtr VARCHAR(4000), OUT lc_str
> VARCHAR(4000))
> LANGUAGE SQL
> BEGIN
> DECLARE SQLSTATE CHAR(5);
> DECLARE lc_colval VARCHAR(4000);
> DECLARE c_refcur INT;
> DECLARE at_end INT DEFAULT 0;
>
> DECLARE not_found CONDITION FOR SQLSTATE '02000';
>
> DECLARE C1 CURSOR FOR S1;
> DECLARE CONTINUE HANDLER FOR not_found SET at_end = 1;
>
> PREPARE S1 FROM p_slct;
>
> SET lc_str = '';
> OPEN C1;
> fetch_loop:
> LOOP
> FETCH C1 INTO lc_colval;
> IF at_end = 1 THEN LEAVE fetch_loop;
> END IF;
> SET lc_str = lc_str || p_dlmtr || lc_colval;
> END LOOP;
> CLOSE C1;
> END
>
> When i try to use it
> CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY',',');
> i got the following error:
> sqlcode: -440
> The parameter mode (IN, OUT, or INOUT) is not valid for a parameter in
> procedure.
>
> How to fix my call?
> Thank's in advance.

Try this:
CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY',''',?);

or this
CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY','@',?);

 >> Stay informed about: Need help with Stored Procedure 
Back to top
Login to vote
lenygold via DBMonster.co

External


Since: Feb 19, 2008
Posts: 80



(Msg. 3) Posted: Wed Mar 12, 2008 10:17 pm
Post subject: Re: Need help with Stored Procedure [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank You it is working.

Mark A wrote:
>> 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
>[quoted text clipped - 42 lines]
>> How to fix my call?
>> Thank's in advance.
>
>Try this:
>CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY',''',?);
>
>or this
>CALL ROWTOCOL('SELECT NAME, DOB FROM FAMILY','@',?);

--
Message posted via DBMonster.com
http://www.dbmonster.com/Uwe/Forums.aspx/ibm-db2/200803/1
 >> Stay informed about: Need help with Stored Procedure 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
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...

stored procedure - Hi, How would i call "runstats" within a stored procedure? Assuming the procedure takes a table name as an input parameter. Thanks in advance. Thanks, Sumanth

Stored Procedure - Hi All: I use db2 v8 fp 14 on Aix. I am facing problems with a stored procedure that is causing a lot of locks and also goes in the lock wait state ending up hanging the application. Tried using the UR isolation mode but it did not help. Can some one....

newbie - function in a stored procedure - I am looking for the syntax to call a function within the stored procedure. For example.... function checkvalue( pv1 ) begin do a lot of stuff... end; Fetch first row; While (something <> EOF) do if (sValue = 5) then ...

z/OS stored procedure doesn't return value - I'm running a java program on a PC which calls z/OS SQL stored procedure. The stored procedure returns an integer which should contain "2", but is always "0". I (pre)compile the stored procedure from the PC using "IBM Data Stud...
   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 ]