- To process an SQL statement, ORACLE needs to create an area of memory known as the context area; this will have the information needed to process the statement.
- This information includes the number of rows processed by the statement, a pointer to the parsed representation of the statement.
- In a query, the active set refers to the rows that will be returned.
- A cursor is a handle, or pointer, to the context area.
- Through the cursor, a PL/SQL program can control the context area and what happens to it as the statement is processed.
- Two important features about the cursor are
-
1.Cursors allow you to fetch and process rows returned by a SELECT statement, one row at a time.
-
There are two types of cursors:
-
1.An IMPLICIT cursor is automatically declared by Oracle every time an SQL statement is executed. The user will not be aware of this happening and will not be able to control or process the information in an implicit cursor.
2.An EXPLICIT cursor is defined by the program for any query that returns more than one row of data. That means the programmer has declared the cursor within the PL/SQL code block.
2.A cursor is named so that it can be referenced.
-
Declaring a cursor defines the name of the cursor and associates it with a SELECT statement.
-
The first step is to Declare the Cursor with the following syntax:
-
CURSOR c_cursor_name IS select statement
- Cursor names follow the same rules of scope and visibility that apply to the PL/SQL identifiers.
- Because the name of the cursor is a PL/SQL identifier, it must be declared before it is referenced.
- Any valid select statement can be used to define a cursor, including joins and statements with the UNION or MINUS clause.