Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Can the FEtch statement used like below

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
pravin madoori

New User


Joined: 29 Jan 2007
Posts: 25
Location: Hyderabad

PostPosted: Tue Sep 23, 2008 6:12 pm    Post subject: Can the FEtch statement used like below
Reply with quote

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
View user's profile Send private message

ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Tue Sep 23, 2008 6:45 pm    Post subject:
Reply with quote

Yes you can ....
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1243
Location: Israel

PostPosted: Tue Sep 23, 2008 7:03 pm    Post subject:
Reply with quote

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
View user's profile Send private message
pravin madoori

New User


Joined: 29 Jan 2007
Posts: 25
Location: Hyderabad

PostPosted: Tue Sep 23, 2008 7:16 pm    Post subject:
Reply with quote

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
View user's profile Send private message
saquib.ahsan

New User


Joined: 22 Sep 2008
Posts: 6
Location: Pune

PostPosted: Tue Sep 23, 2008 9:13 pm    Post subject:
Reply with 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 of the table. same thing applies to the other column. I am not sure if that is what you intend for..
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Sep 24, 2008 1:08 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Fetch Previous month & year in MM... girishb2 DFSORT/ICETOOL 3 Thu Sep 21, 2017 9:54 pm
No new posts WER268A OUTREC STATEMENT : SYNTAX E... frozenblood87 SYNCSORT 12 Sat Aug 26, 2017 9:45 pm
No new posts Suppress value reported by BREAK in D... Learncoholic DFSORT/ICETOOL 3 Wed Aug 16, 2017 6:03 pm
No new posts ON 2 AND EVERY 1 - Statement ??? UmeySan COBOL Programming 2 Tue Jul 25, 2017 1:20 pm
No new posts Need DB2 query to fetch previous row ! Chandan1993 DB2 10 Sat Jun 03, 2017 10:43 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us