473,499 Members | 1,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cursor fetching without declaring host variables... dynamic SQL?

Hi all,

In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.

As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.

Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?

I'm looking for something similar or works similar to the pseudocode
below:

i.e.

DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;

Dec 8 '06 #1
5 8160
Patrick wrote:
Hi all,

In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.

As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.

Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?

I'm looking for something similar or works similar to the pseudocode
below:

i.e.

DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;

When you DECLARE the CURSOR, specify WITH RETURN TO CLIENT, and OPEN
the CURSOR, but do not CLOSE it, before the END of the PROCEDURE.

Ther CLIENT will then get an OPEN CURSOR on all the results.

B.

Dec 8 '06 #2
Hm, what if I need to continue processing inside the procedure?
Brian Tkatch wrote:
Patrick wrote:
Hi all,

In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.

As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.

Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?

I'm looking for something similar or works similar to the pseudocode
below:

i.e.

DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;


When you DECLARE the CURSOR, specify WITH RETURN TO CLIENT, and OPEN
the CURSOR, but do not CLOSE it, before the END of the PROCEDURE.

Ther CLIENT will then get an OPEN CURSOR on all the results.

B.
Dec 8 '06 #3
Patrick wrote:
Hm, what if I need to continue processing inside the procedure?
Brian Tkatch wrote:
Patrick wrote:
Hi all,
>
In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.
>
As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.
>
Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?
>
I'm looking for something similar or works similar to the pseudocode
below:
>
i.e.
>
DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;

When you DECLARE the CURSOR, specify WITH RETURN TO CLIENT, and OPEN
the CURSOR, but do not CLOSE it, before the END of the PROCEDURE.

Ther CLIENT will then get an OPEN CURSOR on all the results.

B.
I do not think it is possible then. You must define host variables.

B.

Dec 8 '06 #4
Patrick wrote:
Hi all,

In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.

As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.

Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?

I'm looking for something similar or works similar to the pseudocode
below:

i.e.

DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;
FOR rowVariable AS SELECT c1, c2, c3... FROM myTable DO
myVariable1 = rowVariable.c1;
myVariable2 = rowVariable.c2;
END FOR;

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 8 '06 #5
Thanks!!!! This is what I was looking for!
Serge Rielau wrote:
Patrick wrote:
Hi all,

In my SQL procedures in DB2 8.2, I current declare several cursors that
return select statements with 10 columns in it.

As a result, assigning host variables becomes a coding mess, as I would
have to declare anywhere from 50-100 host variables just so I can
process them.

Is it possible to fetch the row from a cursor into a single
construct/variable so I can simply access the data by column name?

I'm looking for something similar or works similar to the pseudocode
below:

i.e.

DECLARE CURSOR myCursor AS SELECT c1, c2, c3... FROM myTable;
OPEN myCursor;
FETCH into rowVariable; -- hypothetical, notice I don't have to
define host variables
LOOP
set myVariable1 = rowVariable.c1;
set myVariable2 = rowVariable.c2;
THEN
ITERATE LOOP;
END IF;
FOR rowVariable AS SELECT c1, c2, c3... FROM myTable DO
myVariable1 = rowVariable.c1;
myVariable2 = rowVariable.c2;
END FOR;

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 11 '06 #6

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

Similar topics

1
2376
by: Aakash Bordia | last post by:
Hello, Does anybody know what is the documented and known behavior of inserting/updating binary columns using host variables from a client to a server which have different code pages? Will any...
2
2118
by: Oliver Corona | last post by:
I am wondering if anyone has any insights on the performance benefit (or detriment) of declaring local variables instead of referencing members. Is allocating memory for a new variable more...
0
1515
by: N.V.Dev | last post by:
Hi, Would like to know if I could define function parameters as Host variables; This can be defined in Informix as below int print_table_info ( table_name ) EXEC SQL BEGIN DECLARE...
3
7485
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
13042
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...
16
1961
by: G Patel | last post by:
Hi, If I want to call functions that don't return int without declaring them, will there be any harm? I only want to assign the function(return value) to the type that it returns, so I don't...
2
5588
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...
2
3757
by: majel | last post by:
I just read an older post that described declaring global variables. I tried this but I'm getting an error and the text stays red. What am I doing wrong? This code is behind a form. Thanks. ...
7
13661
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...
0
7225
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...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.