By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,226 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,226 IT Pros & Developers. It's quick & easy.

Dynamic Cursor in DB2

P: 1
Ok, here it is

I need define a cursor having select statement with dynamic where clause.

Please let me know if the query is not clear.

I belive what I am asking is not the Rocket Science.

I need to construct SELECT STATEMENT on the FLY and process the same in CURSOR.

I need something like the code below
************************************************** ************************
MOVE 'SELECT EMPNO, LASTNAME FROM CORPDATA.EMPLOYEE WHERE EMPNO>?'
TO DSTRING.
EXEC SQL PREPARE S2 FROM STRING END-EXEC.

EXEC SQL DECLARE C2 CURSOR FOR S2 END-EXEC.

EXEC SQL OPEN C2 USING :EMP END-EXEC. PERFORM FETCH-ROW UNTIL SQLCODE NOT=0.

EXEC SQL CLOSE C2 END-EXEC.
STOP-RUN.
FETCH-ROW.
EXEC SQL
FETCH C2 INTO :EMP, :EMPNAME END-EXEC.
************************************************** ***********************

I was unable to execute the above code in DB2 Command Centre.
Oct 6 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.