0% found this document useful (0 votes)
35 views5 pages

RDBMS PR 15

1. The document discusses PL/SQL cursors, which are areas of memory used to execute SQL statements and process data through a PL/SQL block. 2. There are two types of cursors: implicit cursors, which are opened by Oracle to execute SQL statements, and explicit cursors, which are opened by the user to process data through a PL/SQL block when multiple records need to be processed individually. 3. The document provides examples of using explicit cursors to transfer account records from one table to another based on branch name.

Uploaded by

uvaishpatla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views5 pages

RDBMS PR 15

1. The document discusses PL/SQL cursors, which are areas of memory used to execute SQL statements and process data through a PL/SQL block. 2. There are two types of cursors: implicit cursors, which are opened by Oracle to execute SQL statements, and explicit cursors, which are opened by the user to process data through a PL/SQL block when multiple records need to be processed individually. 3. The document provides examples of using explicit cursors to transfer account records from one table to another based on branch name.

Uploaded by

uvaishpatla
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

RDBMSPRACTICAL - 15 ENROLLMENT NO:-226010307090

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. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 1


RDBMSPRACTICAL - 15 ENROLLMENT NO:-226010307090

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;

Example of Implicit Cursor:

Aim: In account table, convert the specified branch in to Upper case Letter.
Solution:
DECLARE
CURSOR cacc IS SELECT ANO, BALANCE, BRANCH FROM ACCOUNT2290;
no account2290.ano%TYPE;
balance account2290.balance%TYPE;
branch account2290.BRANCH%TYPE;
BEGIN
OPEN cacc;
IF cacc%ISOPEN THEN
LOOP
FETCH cacc INTO no, balance, branch;
EXIT WHEN cacc%NOTFOUND;
IF branch='VVN' THEN
INSERT INTO acc_vvn values(no, balance);
DELETE FROM ACCOUNT2290 WHERE BRANCH= 'VVN';
END IF;
END LOOP;
COMMIT;
ELSE
dbms_output.put_line('CURSOR CANNOT OPEN');
END IF;
END;

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 2


RDBMSPRACTICAL - 15 ENROLLMENT NO:-226010307090

/
OUTPUT:

To Check the Details of Both Tables these commands can be used.

BEFORE:

AFTER:

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 3


RDBMSPRACTICAL - 15 ENROLLMENT NO:-226010307090

Example of Explicit Cursor:

Aim: Transfer all accounts belongs to ‘vvn’ branch from account table into another table
‘acc_vvn’ having only two collumns acc_no and balance

Solution:

DECLARE
CURSOR cacc IS SELECT ANO, BALANCE, BNAME FROM ACCOUNT22090;
no account22090.ano%TYPE;
balance account22090.balance%TYPE;
branch account22090.BNAME%TYPE;

BEGIN
OPEN cacc;
IF cacc%ISOPEN THEN
LOOP
FETCH cacc INTO no, balance, branch;
EXIT WHEN cacc%NOTFOUND;
IF branch = 'ksad' THEN
INSERT INTO acc_ksad values(no, balance);
DELETE FROM ACCOUNT22090s WHERE BNAME= 'ksad';
END IF;
END LOOP;
COMMIT;
ELSE
dbms_output.put_line('CURSOR CANNOT OPEN');
END IF;
END;
/

OUTPUT:

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 4


RDBMSPRACTICAL - 15 ENROLLMENT NO:-226010307090

BEFORE:

AFTER:

Progressive Assessment Sheet as per Rubrics

Regular Presentation Level of


Attendance Total
Assessment Understanding

05 05 07 08 25

Sign: Date:

A.Y. DADABHAI TECHNICAL INSTITUTE KOSAMBA, SURAT Page 5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy