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

DBMS Exp 10

Uploaded by

Shreya Gokhale
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)
21 views3 pages

DBMS Exp 10

Uploaded by

Shreya Gokhale
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 NO.

10
AIM: To Implement Explicit Cursor
THEORY:
Cursors in PL/SQL
1. Definition of Cursors: A cursor is a database object that allows you to retrieve,
manipulate, and navigate through a result set row by row. It acts as a pointer to a context
area that stores information about the processing of a SQL statement.

2. Types of Cursors: Cursors are primarily classified into two types:


 Implicit Cursors:
o Automatically created by Oracle when a SQL statement is executed.
o Used for single-row queries and do not require explicit declaration.
o Example: A simple SELECT, INSERT, UPDATE, or DELETE statement.
 Explicit Cursors:
o Explicitly declared by the programmer to handle queries that return multiple
rows.
o Provide more control over the context of the result set.
o Can be named and allow for fetching rows one at a time.
o Generally used when you need to process the result set iteratively.

3. Components of an Explicit Cursor: An explicit cursor has the following components:


 Declaration: The cursor is declared with a SQL query that defines the result set. It
specifies the rows that will be retrieved.
SYNTAX:
CURSOR cursor_name IS SELECT statement;
 Opening the Cursor: The cursor is opened to establish the result set based on the
declared SQL query.
SYNTAX:
OPEN cursor_name;
 Fetching Rows: Rows are fetched from the cursor into variables for processing. This is
typically done in a loop until all rows are processed.
SYNTAX:
FETCH cursor_name INTO variable_list;

 Closing the Cursor: After all rows have been processed, the cursor should be closed
to release the resources.
SYNTAX:
CLOSE cursor_name;

4. Usage of Explicit Cursors:


Explicit cursors are particularly useful in scenarios where:
 You need to process multiple rows returned by a query.
 You want to perform complex logic on each row (e.g., calculations, conditional
statements).
 You need to handle result sets dynamically and maintain better control over cursor
operations.

Cursor to Retrieve Accident Details:


Cursor to Retrieve Accident Locations with Counts:

CONCLUSION:
This experiment demonstrated the implementation of explicit cursors in PL/SQL, highlighting
their role in managing and processing multiple rows of data. By exploring cursor types and
their use, we successfully created and utilized explicit cursors, enabling effective row-by-row
data handling. This knowledge enhances our ability to perform complex database operations
efficiently.

You might also like