View previous topic :: View next topic
|
Author |
Message |
pravin madoori
New User
Joined: 29 Jan 2007 Posts: 25 Location: Hyderabad
|
|
|
|
Let I have a table with 5 columns & cursor declaration like below.Does the below FETCH to use a curosor correct?
EXEC SQL DECLARE CSR1 CURSOR FOR
SELECT Col1,col2,col3,col4,col5 FROM table1;
EXEC SQL OPEN CSR1;
EXEC SQL FETCH CSR1 INTO :COL2,:COL3; /*IS IT correct, using only two colums here, where in declaration there were all columns */
DO WHILE (SQLCODE = 0);
EXEC SQL FETCH CSR1 INTO :COL2,:COL3;
END; |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
Yes you can .... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
SQL Reference wrote: |
The first value in the result row is assigned to the first host variable, the second value to the second host variable, and so on. |
Even if this works (which I haven't personally checked yet),
your COL2 variable will receive value of field "col1", and COL3 variable will receive "col2" value.
Maybe that's not exactly what you want ... |
|
Back to top |
|
|
pravin madoori
New User
Joined: 29 Jan 2007 Posts: 25 Location: Hyderabad
|
|
|
|
Yes, I have checked it, the fetch can be used like above but results would be wrong.
If the fetch was like below, it returns correct values to colums 1 & 2.
EXEC SQL FETCH CSR1 INTO :COL1,:COL2; |
|
Back to top |
|
|
saquib.ahsan
New User
Joined: 22 Sep 2008 Posts: 6 Location: Pune
|
|
|
|
I checked this as well and it works fine. However, the value that col2 will receive is the value present in the col1 field of the table. same thing applies to the other column. I am not sure if that is what you intend for.. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello saquib.ahsan and welcome to the forum,
Quote: |
I checked this as well and it works fine. However, the value that col2 will receive is the value present in the col1 field |
It might execute, but i would not call it "fine".
At best it will cause an abend that needs immediate attention. At worst, it may cause data corruption. . . |
|
Back to top |
|
|
|