RDBMS Practical 15
RDBMS Practical 15
PRACTICAL NO: 15
Aim: Implement PL/SQL programs using Cursors.
Description:
Definition:
Types of Cursor:
1. Implicit Cursor
Cursor is called implicit, if it is opened by Oracle itself to execute
any SQL statement.
Example: Convert Specified Branch name in Account Table in Upper case Letter
using cursor.
Solution:
Declare
Branch
2. Explicit Cursor:
Cursor is called explicit cursor, if it is Opened by user to process data
throgh PL SQL Block.
It is used when there is a need to process more than one record Individually.
Steps:
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 1
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 2
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112
1. Declaration of Cursor:
Syntax: CURSOR Cursorname IS SELECT ………….
Example: CURSOR cAcc IS SELECT ano, balance, bname from Account;
2. Open a Cursor:
By Opening Cursor, Allocation Memory, Execute the Select Statement, Create active
data set, Set Row pointer to the First Record in Active Data set.
Syntax: OPEN
Cursorname; Example: OPEN cAcc;
3. Fetching Data:
In this stage, fetch data from active dataset and store in given
variables. Data from single row fetched at a Time.
After fetch current record row pointer updated to the next row in active data set.
Variable should be compitible with the column specified.
4. Close cursor:
Cursor should be closed after processing data. By closing cursor memory
released memory allocated to the cursor.
Syntax: CLOSE
cursorname; Example: CLOSE
cAcc;
Let's create a simple table named EMPLOYEES6001 and demonstrate both types of cursors.
Step 1: Create a table
T
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 3
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112
In PL/SQL, implicit cursors are automatically created when a SELECT statement returns only
one row. Here's a simple example of using an implicit cursor:
An explicit cursor is defined and managed by the programmer. Here's how you can
define and use an explicit cursor to fetch multiple rows from the EMPLOYEES table:
Explicit Cursor:
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 4
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 5
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112
CONCLUSION:
Hence We perform how to Implement PL/SQL programs using Cursors by using
and example
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 6