Multirow Queries with Cursor Variables
Now that you have seen the syntax of OPEN FOR and are familiar with cursor variables, let’s explore the nuances involved in multirow queries with NDS.
When you execute an OPEN FOR statement, the PL/SQL runtime engine does the following:
Associates a cursor variable with the query found in the query string
Evaluates any bind arguments and substitutes those values for the placeholders found in the query string
Executes the query
Identifies the result set
Positions the cursor on the first row in the result set
Zeros out the rows-processed count returned by %ROWCOUNT
Note that any bind arguments (provided in the USING clause) in the query are evaluated only when the cursor variable is opened. This means that if you want to use a different set of bind arguments for the same dynamic query, you must issue a new OPEN FOR statement with those arguments.
To perform a multirow query, you follow these steps:
Declare a REF CURSOR type (if one is not already available, as it could be if defined in a package specification)
Declare a cursor variable based on the REF CURSOR
OPEN the cursor variable FOR your query string
Use the FETCH statement to fetch one row at a time from the query
Check cursor attributes (%FOUND, %NOTFOUND, %ROWCOUNT, %ISOPEN) as necessary
Close the cursor variable using the normal CLOSE statement
Here is a simple program to display the specified column of any table for the rows indicated by the WHERE clause (it will work for number, date, ...