473,322 Members | 1,911 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,322 software developers and data experts.

Cursors, Host Variables in Stored Procedure

DB version - DB2 9.1 on AIX

Consider the following script construct...

open curs1;

fetch curs1 into a, b;

while ( a 0)
begin
set a = -1;
fetch curs1 in to a, b;
end while;
What happens when an end of table is reached? Does a remain -1? If
not, what will it be?
Thanks in advance
Jan 16 '08 #1
3 3865
"Roman" <rg*******@hotmail.comwrote in message
news:08**********************************@y5g2000h sf.googlegroups.com...
DB version - DB2 9.1 on AIX

Consider the following script construct...

open curs1;

fetch curs1 into a, b;

while ( a 0)
begin
set a = -1;
fetch curs1 in to a, b;
end while;
What happens when an end of table is reached? Does a remain -1? If
not, what will it be?
Thanks in advance
Since you did not include the declare cursor, I am not 100% sure how many
columns you have in the fetch.

DB2 will return an SQLCODE 100 when it reaches the end of cursor on a fetch.
Usually, most people handle that with condition handler that sets a variable
to a certain value when the end of cursor (row not found) condition is
reached.
Jan 16 '08 #2
Instead of checking the SQLCODE you can use a FOR loop. An example you
can find here:

http://www.sqlpl-guide.com/FOR

Regards

Michael
Jan 17 '08 #3
<mi************@web.dewrote in message
news:ef**********************************@d21g2000 prf.googlegroups.com...
Instead of checking the SQLCODE you can use a FOR loop. An example you
can find here:

http://www.sqlpl-guide.com/FOR

Regards

Michael
That example is ridiculous. Cursors are typically used to select multiple
rows one at a time, and do something with that row, before fetching the next
row.

That website is full of misinformation, and no person wanting information
about DB2 should ever go there.
Jan 17 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: T.S.Negi | last post by:
Hi All, I want to avoid using cursors and loops in stored procedures. Please suggest alternate solutions with example (if possible). Any suggestion in these regards will be appreciated. ...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
3
by: Anthony Robinson | last post by:
We're encountering an issue with working with CLOB's. We're doing a basic insert into a table that has a CLOB column. Sometimes the CLOB is fairly tame in size (10k-15k), and once in a while...
4
by: Tim.D | last post by:
People, I've ventured into the wonderful world of Stored Procedures. My first experience has been relatively successful however I am stuck on using host variables to specifiy actualy table or...
17
by: vishal | last post by:
I am new to sql and require some help on cursors? what are they and how and why are they used for??? it will be kind enough if anyone helps me in this regards.. regards vishal jain.
12
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very...
2
by: Frank Swarbrick | last post by:
I'm just learning about embedded SQL, so be gentle... My basic question is, if I use a fixed length host variable for a column defined as VARCHAR, will trailing spaces be removed (or not) upon...
7
by: misha | last post by:
Hello. I was wandering if someone could explain to me (or point to some manual) the process of mapping the addresses of host variables by DB2. Especially I would like to know when DB2 decides to...
11
by: Ganesh R | last post by:
Hi Friends... Can anyone plz help me out i'm stuck .... I want to delete multiple records from a data grid using cursors.the parameter for the stored procedure is an comma seperated string(of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.