Preparing the fetch instruction in db2

微信扫一扫,分享到朋友圈

Preparing the fetch instruction in db2

I have been trying to prepare a Fetch statement in db2 as below

Stmt = %trim('FETCH EXSQCRS INTO ?');
EXEC SQL PREPARE SQLSTMT2 FROM :STMT ;

EXSQCRS is a cursor.

But this is failing with -104 error. Any clue on how to write this?

FETCH
isn’t a statement that can be prepared. It’s simply an executable statement. See Actions allowed on SQL statements

You need to read up on Embedded SQL programming

Simple example with dynamic SQL

D EMPNUM          S              6A
 D NAME            S             15A
 D STMT            S            500A   INZ('SELECT LASTNAME         -
 D                                     FROM CORPDATA.EMPLOYEE WHERE -
 D                                     EMPNO = ?')

  //************************************************************
  // Prepare STMT as initialized in declare section            *
  //************************************************************
  /FREE
   EXEC SQL
    PREPARE S1 FROM :STMT;
   //
   //************************************
   // Declare Cursor for STMT           *
   //************************************
   EXEC SQL
    DECLARE C1 CURSOR FOR S1;
   //
   //****************************************************
   // Assign employee number to use in select statement *
   //****************************************************
   EMPNUM = '000110';

   //*********************
   // Open Cursor        *
   //*********************
   EXEC SQL
    OPEN C1 USING :EMPNUM;
   //
   //**********************************************
   // Fetch record and put value of               *
   // LASTNAME into NAME                          *
   //**********************************************
   EXEC SQL
     FETCH C1 INTO :NAME;

微信扫一扫,分享到朋友圈

Preparing the fetch instruction in db2

The best way for Node JS to wait when booting for initialization from the database, e...

上一篇

Test-driven development in Python

下一篇

你也可能喜欢

Preparing the fetch instruction in db2

长按储存图像,分享给朋友