A select cursor

A select cursor enables you to scan multiple rows of data that a SELECT statement returns. The DECLARE statement associates the SELECT statement with the select cursor.

In the DECLARE statement, the SELECT statement can be in either of the following formats:
  • A literal SELECT statement in the DECLARE statement
    The following DECLARE statement associates a literal SELECT statement with the slct1_curs cursor:
    EXEC SQL declare slct1_curs cursor for select * from customer;
  • A prepared SELECT statement in the DECLARE statement
    The following DECLARE statement associates a prepared SELECT statement with the slct2_curs cursor:
    EXEC SQL prepare slct_stmt cursor from
          'select * from customer';
    EXEC SQL declare slct2_curs for slct_stmt;

If the SELECT returns only one row, it is called a singleton SELECT and it does not require a select cursor to execute.