Can you re-use cursors?



IBM's flagship relational database management system

Can you re-use cursors?

Postby dbhasty » Tue May 17, 2011 11:35 pm

Hi

I basically want to know if you can re-use a cursor? If you do you need to close the cursor then re-open it or can you just run the fetch part again.

In working storage i have array/table.
01 WS_TABLE.
05 EMP_NUM X(5)OCCURS 10 TIMES.
05 NAME OCCURS 10 TIMES.



Here is the cursor set up
EXEC SQL DECLARE C1 CURSOR WITH ROWSET POSITIONING FOR
SELECT NAME, EMP-NUM
FROM CORPORATE.EMPLOYEE
WHERE DEPT = :WS-DEPT
END-EXEC.

EXEC SQL OPEN C1 END-EXEC.

EXEC SQL FETCH FIRST ROWSET FROM C1 FOR 10 ROWS INTO :NAME, :EMP-NUM END-EXEC.

EXEC SQL CLOSE C1 END-EXEC.


I want to run it for when WS-DEPT is set to '010' and then run it again for when WS-DEPT is set to '020'. Can this be done using one cursor?


Many thanks
DB
dbhasty
 
Posts: 6
Joined: Fri May 06, 2011 11:05 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Can you re-use cursors?

Postby dick scherrer » Wed May 18, 2011 3:15 am

Hello,

Close the cursor.

Set the new search value.

Open the cursor.
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


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post