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

Assignment 11

This document provides instructions for an assignment to implement different types of cursors in PL/SQL. It begins with the aim of writing a PL/SQL block to use explicit, implicit, scrollable, and insensitive cursors. The theory section defines stored procedures, functions, and cursors. Cursors allow iterating through result sets and processing rows. MySQL cursors are read-only, non-scrollable, and sensitive. An example procedure demonstrates using an explicit cursor to retrieve employee data and classify salaries. Guidelines are provided for students on completing experiments and assessments.

Uploaded by

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

Assignment 11

This document provides instructions for an assignment to implement different types of cursors in PL/SQL. It begins with the aim of writing a PL/SQL block to use explicit, implicit, scrollable, and insensitive cursors. The theory section defines stored procedures, functions, and cursors. Cursors allow iterating through result sets and processing rows. MySQL cursors are read-only, non-scrollable, and sensitive. An example procedure demonstrates using an explicit cursor to retrieve employee data and classify salaries. Guidelines are provided for students on completing experiments and assessments.

Uploaded by

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

ASSIGNMENT NO.

11

Aim

Write a PL/SQL block to implement all types of Cursors

Objective
To study and implement cursor.

Theory

A database stored program (stored module or stored routine) is a computer program that is stored
within and executes within the database server.
When program is executed, it is executed within the memory address of a database server
process or thread.

Syntax

Create procedure example()


Begin
//declare program variables
//statements
End;

Call example1();

To handle a result set inside a stored procedure, you use a cursor. A cursor allows you to iterate a set of
rows returned by a query and process each row accordingly.

MySQL cursor is read-only, non-scrollable and asensitive.

 Read only: you cannot update data in the underlying table through the cursor.
 Non-scrollable: you can only fetch rows in the order determined by the SELECT statement.
You cannot fetch rows in the reversed order. In addition, you cannot skip rows or jump to
a specific row in the result set.
 Asensitive: there are two kinds of cursors: asensitive cursor and insensitive cursor. An
asensitive cursor points to the actual data, whereas an insensitive cursor uses a temporary
copy of the data. An asensitive cursor performs faster than an insensitive cursor because
it does not have to make a temporary copy of data. However, any change that made to the
data from other connections will affect the data that is being used by an asensitive cursor,
therefore, it is safer if you don’t update the data that is being used by an asensitive cursor.
MySQL cursor is asensitive.
Working of Cursor

DECLARE cursor_name CURSOR FOR SELECT_statement;

OPEN cursor_name;

FETCH cursor_name INTO variables list;

CLOSE cursor_name;

Procedure to display status of Employee (explicit cursor)

Delimiter $$
Drop procedure if exists empcursor $$
Create procedure empcursor()
Begin
Declare eno int;
Declare ename varchar(20);
Declare esal int;
Declare flag int default 0;
Declare c1 cursor for select eid, empname, Salary from employee;
Declare continue handler for not found set flag = 1;
Open c1;
emp_loop : loop
Fetch c1 into eno, ename, esal;
If flag = 1 then
Leave Stud_loop;
End if;

if esal < 10000 then


select 'C Class';
elseif esal > 10000 and esal < 20000 then
select 'B Class';
else
select 'A Class';
end if;
End loop emp_loop;
Close c1;
End $$
delimiter ;

Output

 Procedure and function.

References:
1. Raghu Ramkrishanan, Johannes Gehrke 4 th Edition “Database Management Systems” 2. Avi
Silberschatz , Henry F. Korth , S. Sudarshan, “Database System Concepts, Sixth Edition”, ISBN-
13: 978-93-3290-138-4, MCGraw Hill

Frequently Asked Questions

Q. Questions BT CO
No
1 Explain cursors with example? 2 2
2 Explain implicit and explicit cursor? 2 2

Guidelines for Students


The experiments should be completed and get checked by the concerned teacher in the
lab on or before the date of submission. After which the experiment will not be signed.

Every experiment must be included in the file in following format.


a. Aim: In this section write complete objective of the program you are going to make in
the lab. This section specifies the complete description of the including problem analysis,
input description, method used, fundamental concept and desired output format.
b. Theory: Write brief theory related to practical.
c. Algorithm: Write Algorithm for given task.
d. Input: Write input test data/ or program that are used to test program objective to see
whether program is achieving the given objective or not.
e. Output: describe the results in few lines
f. Conclusion: Write complete conclusion whether what the student has learned from this
experiment.
g. Source Code: Submit in the form of soft copies.

 Marking criteria.
Experiment completion (Timely)
Lab file (neatness and regularity)
Viva (from time to time)
Mock Practical Exam
Exam (end term): Practical + Viva

 Assessment Methodology
Timely completion of assignment- 2marks
Program demonstration- 4 marks
Viva-voce -2 marks
Timely submission of journal- 2 marks

You might also like