473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Db2 stored procedure fetch multiple rows

HI!
I MADE A STORED PROCEDURE BUT WHEN I CALL IT ONLY RETURN THE FIRST RECORD AS A MESSAGE, AND DOESNT RETURN ALL THE RECORDS THAT I QUERY.
THIS IS THE CODE:
CREATE PROCEDURE SCHEMA.PROCED21( OUT CVE_PROGRAMA INTEGER, OUT NOMBRE_CARRERA VARCHAR(120) )

RESULT SETS 1

LANGUAGE SQL

NOT DETERMINISTIC

READS SQL DATA

P1: BEGIN

DECLARE ANIOI INTEGER;

DECLARE ANIOF INTEGER;

DECLARE PROGACAD INTEGER;

DECLARE CVE_PROGRAMA_TEMP INTEGER;

DECLARE NOMBRE_CARRERA_TEMP VARCHAR(120);

DECLARE CVE_CARRERA INTEGER;

DECLARE cursor1 CURSOR WITH RETURN TO CALLER FOR

SELECT YEAR (CURRENT TIMESTAMP) FROM sysibm.sysdummy1;

DECLARE cursor2 CURSOR WITH RETURN TO CALLER FOR

SELECT T3.ID_002 FROM SCHEMA.T_046 T1 INNER JOIN SCHEMA.T_118 T3 ON (T1.ID_046=T3.ID_046) INNER JOIN SCHEMA.T_122 T4 ON (T1.ID_122=T4.ID_122 AND INICIO=ANIOI AND FIN =ANIOF);

OPEN cursor1;

FETCH FROM cursor1 INTO ANIOI;

CLOSE cursor1;

SET ANIOF = ANIOI+1;

OPEN cursor2;

FETCH cursor2 INTO PROGACAD;

FOR I AS cursor3 CURSOR WITH HOLD FOR

SELECT T5.ID_001, T5.ID_002 FROM SCHEMA.T_002 T5 WHERE T5.ID_002 =PROGACAD

DO

SET CVE_CARRERA = ID_001;

SET CVE_PROGRAMA_TEMP = ID_002;

FOR J AS cursor4 CURSOR WITH HOLD FOR

SELECT NOMBRE FROM SCHEMA.T_001 WHERE ID_001=CVE_CARRERA

DO

SET NOMBRE_CARRERA_TEMP= NOMBRE;



END FOR;



END FOR;

CLOSE cursor2;

SET CVE_PROGRAMA = CVE_PROGRAMA_TEMP;

SET NOMBRE_CARRERA = NOMBRE_CARRERA_TEMP;

RETURN CVE_PROGRAMA;

END P1;

I WANT TO SEE THE RESULTS AND IN MESSAGE WINDOW ONLY REPORT:

> CALL SCHEMA.PROCED21(?,?)

Return Code = 85

Output Parameter #1 = 85
Output Parameter #2 = ADMINISTRACIÓN

Statement ran successfully (99 ms)

CAN U HELP ME PLEASE?
THXS.
Feb 12 '10 #1
1 8044
Hi,

If you are using DB2/400, this link may help (see chapter 5.5).
http://www.redbooks.ibm.com/redbooks...tml/wwhelp.htm

It suggests that once you have opened the cursor that you want returned, to the calling progam, you issue something similar to:
Expand|Select|Wrap|Line Numbers
  1. DECLARE c1 CURSOR FOR SELECT cusnam FROM customer ORDER BY cusnam;      
  2. OPEN c1;      
  3. SET RESULT SETS CURSOR c1; 
  4.  
Hope this helps,

JP
Feb 26 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: aaj | last post by:
SQL SERVER 2000 Hi all This is my first attempt at writing a stored procedure. I have managed to get it working but its unlikely to be the best way of handling the problem. While writing it I...
4
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
12
by: Lucky | last post by:
Hi guys! i want to create one cursor in the t-sql. the problem is i want to use stored procedure instead of select command in cursor. can anyone tell me how can i use stored procedure's o/p to...
7
by: Roger | last post by:
I am trying to create a stored procedure with following functionality. I need to select a table where status = 'G' and return the row to the application and then update all those rows that I just...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
1
by: db2user99 | last post by:
Hi All, Can anyone please help me figure out the error with these stored Procedures.I am trying to perform large updates.The Updates are being performed but it goes into an infinite loop. ...
5
by: william.david.anderson | last post by:
Hi there, I have a newbie question regarding stored procedures and locking. I'm trying to use a stored procedure to perform a 'select for update' and return a cursor. Below is a stripped down...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.