Cursor Variables and REF Cursors
A cursor variable is a variable that points to or references an underlying cursor. Unlike an explicit cursor, which names the PL/SQL work area for the result set, a cursor variable is a reference to that work area. Explicit and implicit cursors are static in that they are tied to specific queries. The cursor variable can be opened for any query, even for different queries within a single program execution.
Declaring REF CURSOR types
You must perform two distinct declaration steps in order to work with a cursor variable:
Create a referenced cursor TYPE.
Declare the actual cursor variable based on that type.
The syntax for creating a referenced cursor type is as follows:
TYPEcursor_type_nameIS REF CURSOR [ RETURNreturn_type];
where cursor_type_name is the name of the type of cursor, and return_type is the RETURN data specification for the cursor type. The return_type can be any of the data structures valid for a normal cursor RETURN clause and is defined using the %ROWTYPE attribute or by referencing a previously defined record TYPE.
Notice that the RETURN clause is optional with the REF CURSOR type statement. Both of the following declarations are valid:
TYPE company_curtype IS REF CURSOR RETURN company%ROWTYPE;
TYPE generic_curtype IS REF CURSOR;The first form of the REF CURSOR statement is called a strong type because it attaches a record type (or row type) to the cursor variable type at the moment of declaration. Any cursor variable declared using ...