Execute a parameterized SELECT that returns multiple rows

The following sample program shows how to use a dynamic SELECT statement with the following conditions:
  • The SELECT returns more than row.

    The SELECT must be associated with a cursor, executed with the OPEN statement, and have its return values retrieved with the FETCH...USING SQL DESCRIPTOR statement.

  • The SELECT has input parameters in its WHERE clause.

    The OPEN statement includes the USING SQL DESCRIPTOR clause to provide the parameter values in a system-descriptor area.

  • The SELECT has unknown columns in the select list.

    The FETCH statement includes the USING SQL DESCRIPTOR clause to store the return values in a system-descriptor area.