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 > Return out parameter from stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-18-10, 03:31
asp_crazy_guy asp_crazy_guy is offline
Registered User
 
Join Date: Mar 2009
Posts: 73
Red face Return out parameter from stored procedure

Hello guys I want to return the updated record count from my stored procedure. Here is what I have managed so far. I don't understand how to return it through a cursor. Is it necessary at all ?

Code:
CREATE PROCEDURE PAKRETST.FTUMODINST (IN GENFORTREATYSRNO INTEGER,IN GENFTMDPDUENO INTEGER, OUT NUMREC SMALLINT)
RESULT SETS 0 MODIFIES SQL DATA LANGUAGE SQL
P1:BEGIN
    DELCARE strCmd VARCHAR(500);
    DECLARE x CURSOR WITH RETURN TO CALLER FOR SL;
    SET strCmd='UPDATE PAKRETST.UWFTMDPDUEDATES a where a.GENFORTREATYSRNO='||GENFORTREATYSRNO||'AND a.GENFTMDPDUENO='||GENFTMDPDUENO;
    PREPARE SL FROM strCmd;
    SET NUMREC= -- Stuck here --
    RETURN;
    END
    ;
Reply With Quote
  #2 (permalink)  
Old 08-18-10, 03:45
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
You can return the row count as an out parmeter. Here is a SP example:

create procedure update_salary
(in original_salary integer, in new_salary integer, out rows_updated integer)
language sql

begin

update employee set salary = new_salary where salary = original_salary;
get diagnostics rows_updated = ROW_COUNT;

end
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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