Declare a select cursor
To execute a SELECT statement that returns more than one row, you must declare a select cursor. The select cursor enables the application to handle multiple rows that a query returns.
- Declare host variables to receive the values that the database
server returns.
For a prepared SELECT statement, these values are the select-list columns. For a prepared EXECUTE FUNCTION statement, these values are the return values of the user-defined function.
- Assemble and prepare the statement.
A prepared SELECT statement can contain input parameters in the WHERE clause. A prepared EXECUTE FUNCTION statement can contain input parameters as function arguments.
- Declare the select cursor.
The DECLARE statement associates the prepared SELECT statement with the select cursor.
- Execute the query.
The OPEN statement sends any input parameters that its USING clause specifies to the database server and tells the database server to execute the SELECT statement.
- Retrieve the rows of values from the select cursor.
The FETCH statement retrieves one row of data that matches the query criteria.