0% found this document useful (0 votes)
3 views

PLSQL-Cursor1

The document explains the two types of cursors in PL/SQL: Implicit Cursors, which are automatically managed by Oracle for single-row queries and DML operations, and Explicit Cursors, which are user-defined for handling multiple-row queries requiring manual management. Key differences include the need for declaration and control over operations, with Implicit Cursors being faster for single-row operations. It advises using Implicit Cursors for single-row queries and Explicit Cursors for multi-row queries requiring iterative processing.

Uploaded by

vy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PLSQL-Cursor1

The document explains the two types of cursors in PL/SQL: Implicit Cursors, which are automatically managed by Oracle for single-row queries and DML operations, and Explicit Cursors, which are user-defined for handling multiple-row queries requiring manual management. Key differences include the need for declaration and control over operations, with Implicit Cursors being faster for single-row operations. It advises using Implicit Cursors for single-row queries and Explicit Cursors for multi-row queries requiring iterative processing.

Uploaded by

vy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

In PL/SQL, cursors are used to retrieve and process multiple rows from a

database query. There are two types of cursors: Implicit Cursors and
Explicit Cursors.

1. Implicit Cursor

An Implicit Cursor is automatically created by Oracle when a DML


statement (INSERT, UPDATE, DELETE) or a SELECT statement that
returns a single row is executed.

Characteristics of Implicit Cursor:

 Automatically managed by Oracle, no need to declare or open/close it.

 Used for single-row SELECT queries and DML operations.

 Cursor attributes (%FOUND, %NOTFOUND, %ROWCOUNT, %ISOPEN)


can be used to check execution results.


2. Explicit Cursor

An Explicit Cursor is user-defined and is used when a SELECT query


returns multiple rows. The user must declare, open, fetch, and close
the cursor manually.

Characteristics of Explicit Cursor:

 Used for queries returning multiple rows.

 Must be explicitly declared, opened, fetched, and closed.

 Provides better control over row-by-row processing.


Key Differences Between Implicit and Explicit Cursors

Feature Implicit Cursor Explicit Cursor

User-defined for handling multi-


Definition Automatically created by Oracle
row queries

Used for single-row queries


Usage Used for multi-row queries
and DML statements
Feature Implicit Cursor Explicit Cursor

Declaratio Not required (handled


Must be declared explicitly
n internally)

The programmer manages


Oracle controls open, fetch, and
Control open, fetch, and close
close operations
operations

Performan Preferred for row-by-row


Faster for single-row operations
ce processing in multi-row queries

%FOUND, %NOTFOUND, Same attributes available but


Attributes %ROWCOUNT, %ISOPEN can be must be used within the cursor
used scope

When to Use Which?

 Use Implicit Cursor when working with single-row queries or DML


statements.

 Use Explicit Cursor when dealing with multiple-row queries that


require iterative processing.

You might also like