Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2004
    Posts
    2

    Unanswered: 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!!

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •