0% found this document useful (0 votes)
6 views6 pages

RDBMS Practical 15

The document outlines the implementation of PL/SQL programs using cursors, defining cursors as memory areas for executing SQL statements. It describes implicit and explicit cursors, detailing their attributes, declaration, opening, fetching data, and closing processes. Examples are provided for both types of cursors, demonstrating their usage in a practical context.

Uploaded by

ahshamdanawala
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)
6 views6 pages

RDBMS Practical 15

The document outlines the implementation of PL/SQL programs using cursors, defining cursors as memory areas for executing SQL statements. It describes implicit and explicit cursors, detailing their attributes, declaration, opening, fetching data, and closing processes. Examples are provided for both types of cursors, demonstrating their usage in a practical context.

Uploaded by

ahshamdanawala
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/ 6

RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112

PRACTICAL NO: 15
Aim: Implement PL/SQL programs using Cursors.

Description:

Definition:

Cursor is an area in memory where the data stored which is required to


execute sql statement. It means it is the part of the memory.

Attributes of the Cursor:

Name of attribute Description

%ISOPEN If cursor is OPEN, it returns True. Otherwise False

%FOUND If record fetched successfully then returns True otherwise


False
%NOTFOUND If record Not fetched successfully then returns True otherwise
False
%ROWCOUNT It returns the number of Records processed by Cursor

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.

Syntax: FETCH cursorname INTO variable1, variable2…..;


Example: FETCH cAcc INTO no, bal, branch;

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

Step 2: Insert some data into the table

T
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 3
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112

hen Run COMMIT Command;


Implicit Cursor Example

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:

Explicit Cursor Example

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:

How we performed (Explanation):


Implicit Cursor:
Automatically created for single-row SELECT statements.
In the example, SELECT SALARY INTO v_salary fetches the salary of the employee with
EMP_ID = 101.

Explicit Cursor:
A.Y.DADABHAITECHNICALINSTITUTEKOSAMBA,SURAT Page 4
RDBMS PRACTICAL:-15 ENROLLMENT:-236010307112

Defined explicitly using the CURSOR keyword.


In the example, the cursor emp_cursor is defined to fetch all rows from the EMPLOYEES
table, and a loop is used to process each row.

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

You might also like