You are on page 1of 6

Asstgnoent No S.

Tte
itt. OPLisoL bodk.bo inolengnk alk bupesof cusets

Theoy
TntToduckte Eo_UTsOT
A.CMSOI 1S a tempany wOTh anta CTaked in the susten
menoy when SQl tatenent is Ex.ecuke A CGOY Captains intor
na~ioo on.a5elect.stalnent and he ToUs.o.t dalg alltsed
hu 1tAcosox Con bold onc or mave oulsbut:.can praCSS only
one Moa.E aHme. Ihe set ot rouS he cusors holds is.called
thegcHue Set. y SoL Cutso is ead.only.no.n s(alloble and
0sentive

Apes of CTSOTS
Ihest 0Kt to types 6fcitOKS in PLSQL
Inplicit (usoYS
Ihcse axc Crealrd by default ehen DnL Stalenents k c
LNSERT,UR09TE and DELETE Siakemers 0e ecbtdht4.aunt
alsa.created when aSELECT 5takement Bhatrektms just
Onexotw is execubtd

Eplidt CUSOiS
Ibeu.must be created uhen gou a texecuing a SELECT
Stakesnentthak Teums moe bhal oneTow Cuen Bhotugh Ehe
sa1 Stoxes nuktple Tcods, 0ny Ohe xecoid can bepiocessed
dta ktmeuhich is Caled as comenttow Even Ehotah EhC
Cment Tow position
moVes to the pextTo bath
enp lidt CuTSOTs haue Hhe same fondtionali Eyinpliut
Ehe wy Ehty ast accesed. but
Uhn uou eecube
00L stakesnen uuke DELEIE, TNss
UPDATE 1S|ECT Stalements Impliüt stairnents
ptecess Bhese Statements Onace psauides aat ckalta
LuSO to check Ehe 5takus of the DnL tuatnibubs i
aseY attai bulks ore 0Aabl
Operaionshu

Gcneral Suntok ot UsOi with etample


Iist_uauhaxe ba dedarc aCUsoibyusing thc DECLA
Statement
DECLARE Cusat-name CURsaR FoR
SELECEstokee
he cuso1 decombtan must be aHteranu
yonioble de
onlt musE aluaps be assocattd.usibEh SELECT statenal

Net uou Open Ehe uisa bu using he OPEN


OXEN stkrnent iptalizes bhe Tesut setfor Bhe starant.
cussax
Ehexcoveyou pntis bE catl Bhe OPEN Stgkement before
tething uou ows 10m Ehe nesult set
OPEN LUTSO-Name
hen spu us Ene aCH stadement to
Tehievehe
Pointrd by the SoY 6f move the cSOx ta nebou
Ehe nelE
FEICH CUGOT-0omeTNI0 Joíiaboles iSL
Aft that, gotL.Can Check to see if there 15 any Tow
nilable befote fckhing
autilable beore it.Fnaluy-uCu call the CLoSE
Sttenents o decacHibte the CuNseY and relnse. Ehe. memory
nspclatdulthit as_ follow
CLCSE uTSOYName,

pat decoc a
wln ysQL cUGO1, ua must
ohen UwOIKing when the cuTsOY
handles bo bandle the siuaton
AMT FOUND
tine ou call the
any Tow-becaLe_each
nd couldot tnd
aNond
nex Totu
stotementhe curser attenps to sad Bhe
FETCH dataand.a
inthe Toult Set.itwill pot be oble to get the condlHon.
handles S Used to randle this
Condttien G 1a15ed. The

handles, tou t e the following eniox


NOT founuD
Todeclae a FOUND SET
DECLARE (OMTINUE HANOLER FOR NOT

Hnished the cuso


a vantable to indicate hat
where Hnished-1s seb.
he end of he esult
has Teached
Bhat he hondler declaration
must appeaafte
Notice stoTed proceduns.
decloabio0 inside the
Ubniable and cLso
The tollowing dnA
Tardcheus heuySQLcuson LuorS:

No

DFCLARE laPENFEICH ÉneTY -yes


HA
COnclasion
Hence we hawe studicd and impemenbed
bedhe SQL CC
mysql> create
te tab table 0_Roll (RollNo int, Name varchar (30), Age int)
aftected (0.07 sec)
mys Ok,k, 0 rrows
0 ows

Query

vaate table N_Roll (RollNo int, Name varchar (30),Age int)


rows affected (0.07 sec)
mysOK,
Query Ok, 0

ll
insert into 0_Rol values (1, 'Pratik', 20) , (2, 'Suraj',21), (3, "Ambar',21)
mysql
attected (0.04 sec)
OK, 3 ows
ery
Duplicates: 0 Warnings: 0
Records: 3

vsql>
select
*
from 0 Roll;
T

RollNo Name Age


T

1 Pratik| 20
2 Suraj 21
3I Ambar 21

in s e t (0.00 sec)
3 rows

'Yogesh', 21) (6, 'Jeet', 19) ;

mvsql> insert
into N_Roll values (4, 'Abhi',20) , (5, ,

3 rows affected (0.04 sec)


Query OK,
Duplicates: 0 Warnings : 0
Records: 3

mysql>
select
*
from N Roll;
--+

RollNo Name Age


--+-

Abhi 20
5 Yogesh 21
6 Jeet 19
-= T

in s e t (0.00 sec)
3 rows

mysql> delimiter //
CursorProc3 0
create procedure
mysql>
begin 0;
declare rol int default
nme
varchar (20) ;
declare
default 0;
declare ag i n t
declare roll int default 0
(20) ;
varchar
d e c l a r e nmel
d e f a u l t 0;
d e c l a r e agl i n t
False;
d e c l a r e done
int d e f a u l t
0; from 0_Roll;
int default RollNo, Name, Age
declare Not_dup select
distinct
from N_Roll;
tcursor
cursor for
distinct RollNo, Name, Age
declare
cursor for s e l e c t done=True;
declare
scursor
FOUND SET
HANDLER FOR NOT
CONTINUE
DECLARE
open scursor ;

loop1:loop into roll, nmel,


agli
scursor
retch
f done then leave loopl;
end if;
open tcursor?
read loop:loop
etch teursor into rol,nme, ag
if done the leave read loop
end i f

end 1o0p read loop;


f Not dup=l then set
Not dup-0:
else insert into
ORoll values (rol1,
end iE; nmel, agl) ;
close t c u r s o r ;
set done=False;
end loop loopl;
close sCursor;

end/
Query OK, 0 rOws affected (0.00 sec)

mysql> call0 CursorProc () /


Query OK, rOwS affected, 1 warning (0.10 sec)
mysql> select * from O Roll;//

+ ----4--------4
IRollNo | Name IAge
+- +--------+-----+
I Pratik | 20 1
21 Suraj 21
Ambar 21
Abhi 201
51 Yogesh 1 21 1
61 Jeet 19
--

6 rows in set (0.00 sec)

You might also like