Oracle 9i Cursor
Oracle 9i Cursor
CURSOR
For every SQL statement execution certain area in memory is allocated. PL/SQL al
low you to name this
area. This private SQL area is called context area or cursor. A cursor acts as a
handle or pointer into
the context area. A PL/SQL program controls the context area using the cursor. C
ursor represents a
structure in memory and is different from cursor variable.
When you declare a cursor, you get a pointer variable, which does not point any
thing. When the
cursor is opened, memory is allocated and the cursor structure is created. The c
ursor variable now
points the cursor. When the cursor is closed the memory allocated for the cursor
is released.
Cursors allow the programmer to retrieve data from a table and perform actions o
n that data one row
at a time. There are two types of cursors implicit cursors and explicit cursors.
Implicit cursors
For SQL queries returning single row PL/SQL declares implicit cursors. Implicit
cursors are simple
SELECT statements and are written in the BEGIN block (executable section) of the
PL/SQL. Implicit
cursors are easy to code, and they retrieve exactly one row. PL/SQL implicitly d
eclares cursors for all
DML statements. The most commonly raised exceptions here are NO_DATA_FOUND or
TOO_MANY_ROWS.
Syntax:
SELECT ename, sal INTO ena, esa FROM EMP WHERE EMPNO = 7844;
Note: Ename and sal are columns of the table EMP and ena and esa are the variabl
es
used to store ename and sal fetched by the query.