If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Dynamic Cursor in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-07, 16:29
ajexpert ajexpert is offline
Registered User
 
Join Date: Jun 2004
Posts: 2
Dynamic Cursor in DB2

Ok, here it is

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

Hi Guys,
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.

PLEASE HELP!!
Reply With Quote
  #2 (permalink)  
Old 10-07-07, 06:40
guyprzytula guyprzytula is offline
Registered User
 
Join Date: Jun 2006
Posts: 471
you can not execute these stmts in command center
in cmd center, you can only execute select/up/ins/del or call stmt
you need a stored procedure for this, returning the data you need
__________________
Best Regards, Guy Przytula
DB2 UDB LUW certified V6/7/8
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On