SQL Query and FETCH clause

A query may be issued by either defining a cursor or a direct query where only one row is expected. The syntax for the later case is shown below.

   <query> ::= 
         'SELECT' <column list> 
             'INTO' <host variable list>
             'WHERE'...... rest of query ......
         ;

   <host variable list> ::= 
           <variable> [ ['INDICATOR'] <variable> 
         | <host variable list>
         | <empty>
         ;

   <variable> :: = ':' <identifier> ;

   

The esql handles this statement as a normal SQL statement but removing the 'INTO' clause from the SQL string which is sent to the dbcs. The host variables listed in the <host variable list> are used to store the columns of the query result.

   <fetch clause;> ::= 
         'FETCH' 
             [ 'FROM' <cursor> 
             | 'USING' [ 'STATEMENT' ] <statementname> ]
            'INTO' <host variable list>
          ;
   

Either a cursor name or a statement name (see dynamic sql) may be given as a source for the fetch command.