Page 1 of 1

db2 cursor

PostPosted: Thu Dec 29, 2011 7:22 pm
by gabbar
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

Re: db2 cursor

PostPosted: Fri Dec 30, 2011 11:27 am
by dick scherrer
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.

Re: db2 cursor

PostPosted: Mon Jan 02, 2012 11:46 am
by Nik22Dec
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.