0% found this document useful (0 votes)
4 views3 pages

Manual Experiment 2.3

The document provides an introduction to cursors in Oracle Database, explaining their role in managing the context area for SQL statements. It distinguishes between implicit and explicit cursors, detailing their characteristics and usage in PL/SQL programming. The document outlines the steps for working with explicit cursors, including declaring, opening, fetching, and closing them.

Uploaded by

Vedant Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Manual Experiment 2.3

The document provides an introduction to cursors in Oracle Database, explaining their role in managing the context area for SQL statements. It distinguishes between implicit and explicit cursors, detailing their characteristics and usage in PL/SQL programming. The document outlines the steps for working with explicit cursors, including declaring, opening, fetching, and closing them.

Uploaded by

Vedant Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 2.

3
AIM: Introduction and implementation of programs using Cursors.
S/W Requirement: Oracle Database Express Edition

Cursors
Oracle creates a memory area, known as context area, for processing an SQL statement,
which contains all information needed for processing the statement, for example, number of
rows processed etc.

A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor.
A cursor holds the rows (one or more) returned by a SQL statement. The set of rows the
cursor holds is referred to as the active set.

You can name a cursor so that it could be referred to in a program to fetch and process the
rows returned by the SQL statement, one at a time. There are two types of cursors:

Cursors

Implicit Explicit
Implicit Cursors
Implicit cursors are automatically created by Oracle whenever an SQL statement is executed,
when there is no explicit cursor for the statement. Programmers cannot control the implicit
cursors and the information in it.
Whenever a DML statement (INSERT, UPDATE and DELETE) is issued, an implicit cursor
is associated with this statement.
Attribute Description

Returns TRUE if an INSERT, UPDATE, or DELETE statement affected one


%FOUND or more rows or a SELECT INTO statement returned one or more rows.
Otherwise, it returns FALSE.

The logical opposite of %FOUND. It returns TRUE if an INSERT, UPDATE,


%NOTFOUND or DELETE statement affected no rows, or a SELECT INTO statement
returned no rows. Otherwise, it returns FALSE.
Always returns FALSE for implicit cursors, because Oracle closes the SQL
%ISOPEN
cursor automatically after executing its associated SQL statement.

Returns the number of rows affected by an INSERT, UPDATE, or DELETE


%ROWCOUNT
statement, or returned by a SELECT INTO statement.

Explicit Cursors
Explicit cursors are programmer defined cursors for gaining more control over the context
area. An explicit cursor should be defined in the declaration section of the PL/SQL Block. It
is created on a SELECT Statement which returns more than one row.

Syntax
Working with an explicit cursor involves four steps:

o Declaring the cursor for initializing in the memory


o Opening the cursor for allocating memory
o Fetching the cursor for retrieving data
o Closing the cursor to release allocated memory

Declaring the Cursor


Declaring the cursor defines the cursor with a name and the associated SELECT statement.
For example:
CURSOR c_customers IS SELECT id, name, address FROM customers;

Opening the Cursor


Opening the cursor allocates memory for the cursor, and makes it ready for fetching the rows
returned by the SQL statement into it. For example :
OPEN c_customers;

Fetching the Cursor


Fetching the cursor involves accessing one row at a time. For example:
FETCH c_customers INTO c_id, c_name, c_addr;

Closing the Cursor


Closing the cursor means releasing the allocated memory. For example, we will close above
opened cursor as follows:
CLOSE c_customers;

EXAMPLE

--

You might also like