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.