db2 cursor



IBM's flagship relational database management system

db2 cursor

Postby gabbar » Thu Dec 29, 2011 7:22 pm

After the decleration of the cursor with a where condition, how can i fetch each row which satisfies the condition ?
I have used this,
EXEC SQL
DECLARE CSR2 SCROLL CURSOR
FOR SELECT BROKER_ID,BROKER_DET
FROM xxxxxx.BROKER_INFO
WHERE BROKER_TYPE='BR-CITY'
END-EXEC
EXEC SQL
FETCH ABSOLUTE :N CSR2 INTO :HS-BROKER-ID, :HS-BROKER-DET
END-EXEC

please suggest a fetch query
gabbar
 
Posts: 12
Joined: Fri Dec 23, 2011 11:49 am
Has thanked: 0 time
Been thanked: 0 time

Re: db2 cursor

Postby dick scherrer » Fri Dec 30, 2011 11:27 am

Hello,

What happened when you ran the code?

Why specify ABSOLUTE?

Hopefully, there is considerably more code involved and not only these 2 statements. . . No need to post the tntire code at this point, just confirming that there is an actual process written, not just 2 sql statements.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: db2 cursor

Postby Nik22Dec » Mon Jan 02, 2012 11:46 am

Hi,

As far as I could understand, the SQL Query would return all the rows which satisfy the criteria. FETCH ABSOLUTE n fetches the nth row from the first row in the cursor if n is a positive integer. If n is a negative integer, the row n rows before the end of the cursor is fetched. If n is 0, no rows are fetched.

Try this...

EXEC SQL
FETCH CSR2 INTO :WS-BROKER-ID,:WS-BROKER-DET
END-EXEC

You would need to declare the WS-BROKER-ID,WS-BROKER-DET variables in your working storage section.
Thanks,
Nik
User avatar
Nik22Dec
 
Posts: 68
Joined: Mon Dec 26, 2011 6:38 pm
Has thanked: 2 times
Been thanked: 0 time


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post