PL SQL Interview
PL SQL Interview
CURSOR
For every SQL statement execution certain area in memory is allocated. PL/SQL allow
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. Cursor 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
cursor 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 on that
data one row at a time. There are two types of cursors implicit cursors and explicit
cursors.
A cursor variable is a pointer that distinguishes the current row in a resultset from a
multi-row query. Cursor variables have several advantages over explicit cursors
including:
• Cursor variables can point to a variety of queries provided the queries have a
suitable return type. In contrast, explicit cursors are tied to individual queries.
• Cursor variables allow cursors to be opened independently of being processed.
• Cursor variables can be passed as parameters between application layers, as well
as between server side components.
• Cursor variables can be used to reduce client-server network traffic by allowing
several cursors to be opened on the server in a single round trip.
Source:
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/overview.htm#LNP
LS001