Está en la página 1de 65

STUDY OF SQL QUERIES

DATA DEFINITION LANGUAGE


The DDL commands are:
Create Table Alter Table Drop Table Create View Drop View

EMPLOYEE DETAILS: TABLE STRUCTURE


FIELD NAME EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % DATA TYPE NUMBE A"P#ANUME IC A"P#ANUME IC A"P#ANUME IC NUMBE SIZE ! $! $! $! $)

1. Create Comman : !
S"nta#:
create table * table name+ ,col-mn.name data t/pe ,si0e1 constraints12

De$%r&'t&on:
The create command when applied with abo3e speci4ication creates the 4ields o4 di44erent data t/pe5

(. A)ter Comman :!
S"nta#:
a1 alter table *table name+ add,col-mn.name data t/pe ,si0e112

De$%r&'t&on:
The alter command when -sed with add allows -s to add an additional col-mn to an alread/ e6istin7 table5

S"nta#:
b1 alter table *table name+ modi4/,col-mn.name data t/pe ,si0e112

De$%r&'t&on:
The alter command when -sed with modi4/ rede4ines the col-mn with the 7i3en 3al-es col-mn names5 b-t cannot chan7e the

S"nta#:
a1 alter table *table name+ drop,col-mn.name12

De$%r&'t&on:
The alter command when -sed with drop deletes the speci4ied col-mn in the table5

*. Dro' Comman :!
S"nta#:
Drop Table *Table_Name+ 2

De$%r&'t&on:
A table can be dropped ,deleted1 b/ -sin7 a drop table command5

+. Create ,&e- Comman :!


S"nta#:
Create 3iew *3iew.name + as select *col-mn.name 8 9 + 4rom *table.name+where *condition+

De$%r&'t&on:
A 3iew is named: deri3ed: 3irt-al table5 A 3iew ta;es the o-tp-t o4 a <-er/ and treats it as a table2 there4ore: a 3iew can be tho-7ht o4 as a =stored <-er/ = or a =3irt-al table>5 The tables -pon which a 3iew is based are called base tables5

.. Dro' ,&e- Comman :!


S"nta#:
Drop 3iew *3iew.name+

De$%r&'t&on:
A View can be dropped ,deleted1 b/ -sin7 a drop 3iew command5

/. Tr0n%ate Comman :
S"nta#:
Tr-ncate table *table.name+2

De$%r&'t&on:
The details in the table is deleted b-t the table str-ct-re remains5

1. Rename Comman :
S"nta#:
ename *oldtable.name+ to *newtable.name+2

De$%r&'t&on:
The old table name is replaced with the new table name5

PROGRAM TO LEARN DDL COMMANDS

CREATE TABLE:
&?"+ create table empp,emp_id n-mber,!1:emp_name 3archar,$!1:cit/ 3archar,$!1:desi7nation 3archar,$!1:salar/ n-mber,$!112 Table created5 &?"+ desc empp2 Name N-ll@ T/pe ......................................... ........ ....................... EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,$!1

ALTER TABLE:
&?"+ alter table empp add,doA date:basic n-mber,$B:)112 Table altered5 &?"+ desc empp2 Name N-ll@ T/pe ......................................... ........ .................. EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,$!1 D(C DATE BA&IC NUMBE ,$B:)1 &?"+ alter table empp modi4/,salar/ n-mber,D112 Table altered5 &?"+ desc empp2 Name N-ll@ T/pe ......................................... ........ ............................ EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,D1 D(C DATE BA&IC NUMBE ,$B:)1 &?"+ alter table empp drop,doA:basic12 Table altered5

&?"+ desc empp2 Name N-ll@ T/pe ......................................... ........ ............................ EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,D1

CREATE ,IE2:
&?"+ create 3iew empp3iew as select 9 4rom empp2 View created5 &?"+ desc empp 3iew2 Name N-ll@ T/pe ......................................... ........ ............................ EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,D1

DROP ,IE2:
&?"+ drop 3iew empp3iew2 View dropped5 &?"+ desc empp3iew2 E ( : ( A.B!B!E: obAect empp3iew does not e6ist

DROP TABLE:
&?"+ drop table empp2 Table dropped5

TRUNCATE COMMAND:
&?"+ tr-ncate table empp2 Table tr-ncated5 &?"+desc empp2 Name N-ll@ T/pe ......................................... ........ ............................ EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,$!1 &?"+rename empp to emplo/2 Table renamed5 &?"+ desc empp2 E ( : ( A.B!B!E: obAect empp does not e6ist

&?"+desc emplo/2 Name N-ll@ T/pe ......................................... ........ ............................ EMP_ID NUMBE ,!1 EMP_NAME VA C#A ),$!1 CIT% VA C#A ),$!1 DE&I'NATI(N VA C#A ),$!1 &A"A % NUMBE ,$!1

RESULT:
Th-s the DD" command are e6ec-ted and 3eri4ied5

DATA MANIPULATION LANGUAGE

The DML commands are: Insert Delete Update

1. In$ert:
S"nta#:
Insert into *table.name+ 3al-es ,3al$: 3al): 3alE:F5:3aln12

De$%r&'t&on:
The Ginsert intoH command insert the 3al-es in the speci4ied table 5In the insert into &?" sentence the col-mns and 3al-es ha3e a one to one relationship ,i5e1 the 4irst 3al-e described into the 4irst col-mn: the second 3al-e described bein7 inserted into the second col-mn and so on5

(. De)ete:
S"nta#:
Delete 4rom *table.name+ Iwhere *condition+J2

De$%r&'t&on:
The delete in &?" is -sed to remo3e rows 4rom table5 To remo3e $5 All the rows 4rom a table5 ,(r1 )5 A select set o4 rows 4rom a table5

*. U' ate:
S"nta#:
Update *table.name+ set 4ieldnameK*e6pression+ Iwhere conditionJ2

De$%r&'t&on:
The -pdate command is -sed to chan7e or modi4/ data 3al-es in a table5 To -pdate $5 All the rows 4rom a table5 ,(r1 )5 A select set o4 rows 4rom a table5

PROGRAM TO LEARN DML COMMANDS


INSERT COMMAND:
&?"+ insert into empp 3al-es ,Lemp_id:MLemp_nameM:MLcit/M:MLdesi7nationM:MLsalar/M12 Enter 3al-e 4or emp_id: $BB Enter 3al-e 4or emp_name: Aames Enter 3al-e 4or cit/: ban7alore Enter 3al-e 4or desi7nation: modleader Enter 3al-e 4or salar/: )BBBB

old $: insert into empp 3al-es ,Lemp_id:MLemp_nameM:MLcit/M:MLdesi7nationM:MLsalar/M1 new $: insert into empp 3al-es,$BB:MAamesM:Mban7aloreM:MmodleaderM:M)BBBBM1 $ row created5 &?"+ 8 Enter 3al-e 4or emp_id: $B$ Enter 3al-e 4or emp_name: 7anesh Enter 3al-e 4or cit/: chennai Enter 3al-e 4or desi7nation: so4ten7i Enter 3al-e 4or salar/: )$BBB old $: insert into empp 3al-es,Lemp_id:MLemp_nameM:MLcit/M:MLdesi7nationM:MLsalar/M1 new $: insert into empp 3al-es,$B$:M7aneshM:MchennaiM:Mso4ten7iM:M)$BBBM1 $ row created5 &?"+ 8 Enter 3al-e 4or emp_id: $BE Enter 3al-e 4or emp_name: pri/a Enter 3al-e 4or cit/: calc-tta Enter 3al-e 4or desi7nation: mana7er Enter 3al-e 4or salar/: NBBBB old $: insert into empp 3al-es ,Lemp_id:MLemp_nameM:MLcit/M:MLdesi7nationM:MLsalar/M1 new $: insert into empp 3al-es,$BE:Mpri/aM:Mcalc-ttaM:Mmana7erM:MNBBBBM1 $ row created5 &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai so4ten7i )$BBB $BE pri/a calc-tta mana7er NBBBB

UPDATE COMMAND:
&?"+ -pdate empp set desi7nationKMen7ineerMwhere emp_idK$B$2 $ row -pdated5 &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ................. $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $BE pri/a calc-tta mana7er NBBBB

DELETE COMMAND:
&?"+ delete 4rom empp where emp_idK$BB2 $ row deleted5 &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $B$ 7anesh chennai en7ineer )$BBB

$BE

pri/a

calc-tta

mana7er

NBB

RESULT: Th-s the DM" commands are e6ec-ted and 3eri4ied5

DATA ?UE % "AN'UA'E


The DQL commands are: &elect 'ro-p b/ #a3in7 (rder b/ N-ll

1. Se)e%t Statement:
S"nta#:
&elect *attrib-te list+ 4rom *table list+Iwhere cla-seJ2

De$%r&'t&on:
&elect command is -sed to retrie3e data 4rom one or more tables or col-mns5 The attrib-te list is a list o4 attrib-tes name whose 3al-es are displa/ed b/ <-er/5 A missin7 where cla-se indicate no condition on t-ple selection5 The condition is a Boolean e6pression that identi4ies the t-ples to be retrie3ed b/ the <-er/5

D&$t&n%t C)a0$e: S"nta#:


&elect distinct *col-mn name+ 4rom *table name+2

De$%r&'t&on:
Displa/s the distinct 3al-es 4rom a table b/ eliminatin7 the d-plicate 3al-es5 It per4orms 'ro-pin7 o4 the speci4ied 4ields when <-eried with distinct statement5

(. Or er B" C)a0$e:
S"nta#:
&elect *col-mn name+ 4rom *table name+ order b/ *col-mn name+2

De$%r&'t&on:
(rder B/ sorts the o-tp-t o4 an/ speci4ied col-mn or e6pression5 The (rder B/ cla-se m-st alwa/s ha3e tas; in an/ select statement5 The de4a-lt order is ascendin7 order5 we sho-ld speci4/ the ;e/word GdescH i4 we want it in descendin7 order5

*. Gro0' B" C)a0$e:


S"nta#:
&elect *col-mn name+ 4rom *table name + 7ro-p b/ *col-mn name+2

De$%r&'t&on:
5 The 'ro-p B/ cla-se speci4ies the 7ro-pin7 o4 4-nction to appear in the select cla-se5 &o that the 3al-e res-ltin7 4rom 7ro-p o4 t-ples appear alon7 with the 3al-es o4 7ro-pin7 attrib-tes are &UM :AVE A'E : MAO: MIN: C(UNT:&TDDEV

+. 3a4&n5 C)a0$e:
S"nta#:

&elect *col-mn name+ 4rom *table name+ where *condition+ 'ro-p b/ *condition+ ha3in7*condition+2

De$%r&'t&on:
The Gha3in7H cla-se is -sed to speci4/ certain conditions on rows: retrie3ed b/ -sin7 7ro-p b/ cla-se5 This cla-se sho-ld be preceded b/ a G7ro-p b/H cla-se5

.. N0)) Comman :
S"nta#:
&elect *col-mn.name+ NV",s-bstit-tion col-mn:s-bstit-ted 3al-e1 4rom *table name+ where *condition+2

De$%r&'t&on:
The NV" 4-nction helps in s-bstit-tin7 the 3al-e in the n-ll 4ields5b-t this 4-nction onl/ displa/s the chan7e and does not -pdate the col-mns5

PROGRAM TO LEARN DQL COMMANDS SELECT COMMAND:


&?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ............. .... .............. .............. .......... ............ $BB Aames ban7alore modleader )BBBB $B$ $B) $BE $B! $BN 7anesh pri/a ;amal 3ishn;irthi;a chennai calc-tta coimbatore bomba/ chennai en7ineer mana7er proAlead ceo acco-ntant )$BBB NBBBB !BBBB $NBBB $NBBB

P rows selected5

SELECT AND 23ERE CLAUSE: 1. L&$t o-n em')o"ee re%or $ -6o$e $a)ar" &$ 71.888. &?"+ select 9 4rom empp where salar/+$NBBB2 EMP_ID EMP_NAME CIT%DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $B) pri/a calc-tta mana7er NBBBB $BE ;amal coimbatore proAlead !BBBB (. L&$t o-n t6e em'9& :em')o"ee name an $a)ar" ;&e) $. &?"+ select emp_id:emp_name:salar/ 4rom empp2

EMP_ID EMP_NAME &A"A % .......... .............. ........................... $BB Aames )BBBB $B$ 7anesh )$BBB $B) pri/a NBBBB $BE ;amal !BBBB $B! 3ishn$NBBB $BN ;irthi;a $NBBB P rows selected5

SELECT!ORDER BY: *. L&$t o-n t6e em')o"ee $a)ar" &n a$%en &n5 or er. &?"+ select 9 4rom empp order b/ salar/2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $BE ;amal coimbatore proAlead !BBBB $B) pri/a calc-tta mana7er NBBBB P rows selected5 +. L&$t o-n t6e em')o"ee $a)ar" &n e$%en &n5 or er. &?"+ select 9 4rom empp order b/ salar/ desc2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $B) pri/a calc-tta mana7er NBBBB $BE ;amal coimbatore proAlead !BBBB $B$ 7anesh chennai en7ineer )$BBB $BB Aames ban7alore modleader )BBBB $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB P rows selected5 SELECT DISTINCT: &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % ........... ................. .............. .............. .......... ............. $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $B) pri/a calc-tta mana7er NBBBB $BE ;amal coimbatore proAlead !BBBB $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB $BP s-bbomba/ en7ineer )NBBB $BQ pri/a ban7alore ceo )BBBB D rows selected5

&?"+ select distinct cit/ 4rom empp2 CIT% .............. ban7alore bomba/ calc-tta chennai coimbatore SELECT < GROUP BY: &?"+ select desi7nation: ma6,salar/1 4rom empp 7ro-p b/ desi7nation2 DE&I'NATI(N MAO,&A"A %1 .............. .............................. acco-ntant $NBBB ceo )BBBB en7ineer )NBBB mana7er NBBBB modleader )BBBB proAlead !BBBB P rows selected5 SELECT < 3A,ING CLAUSE: &?"+ select ma6,salar/1:min,salar/1:s-m,salar/1 4rom empp 7ro-p b/ desi7nation ha3in7 desi7nationKMceo M2 MAO,&A"A %1 MIN,&A"A %1 &UM,&A"A %1 ....................................... ........... .............. )BBBB $NBBB ENBBB NULL COMMAND: &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... .............. .............. .............. ............................ $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $B) pri/a calc-tta mana7er NBBBB $BE ;amal coimbatore proAlead !BBBB $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB $BP s-bbomba/ en7ineer )NBBB $BQ 3iAa/ ban7alore ceo )BBBB D rows selected5 &?"+ select emp_id:NV",emp_name:Mpri/aM14rom empp whereemp_id K$BQ EMP_ID NV",EMP_NAME: Mpri/aM1 .......... ..................................... $BQ pri/a &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT%DE&I'NATI(N &A"A % .......... .............. .............. ......................... .............

$BB $B$ $B) $BE $B! $BN $BP $BQ

Aames 7anesh pri/a ;amal 3ishn;irthi;a s-b3iAa/

ban7alore chennai calc-tta coimbatore bomba/ chennai bomba/ ban7alore

modleader en7ineer mana7er proAlead ceo acco-ntant en7ineer ceo

)BBBB )$BBB NBBBB !BBB $NBBB $NBBB )NBBB )BBBB

D rows selected5 BET2EEN CLAUSE: &?"+ select 9 4rom empp2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... .............. .............. .............. ............................ $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer $BBB $B) pri/a calc-tta mana7er NBBBB $BE ;amal coimbatore proAlead QPBB $B! 3ishnbomba/ ceo NBBB $BN ;irthi;a chennai acco-ntant $NBBB P rows selected5 &?"+ select 9 4rom empp where salar/ between )BBBB and NNBBB2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... .............. .............. .............. ........................... $BB Aames ban7alore modleader )BBBB $B$ 7anesh chennai en7ineer )$BBB $B) pri/a calc-tta mana7er NBBBB

&?"+ select 9 4rom empp where salar/ not between )BBBB and NNBBB2 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... .............. .............. .............. ............................ $BE ;amal coimbatore proAlead NQPBB $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB

IN AND NOT IN PREDICATE: &?"+ select 9 4rom empp where cit/ in ,MchennaiM:Mbomba/M12 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... .............. .............. .............. ............................ $B$ 7anesh chennai en7ineer )$BBB $B! 3ishnbomba/ ceo $NBBB $BN ;irthi;a chennai acco-ntant $NBBB &?"+ select 9 4rom empp where cit/ not in ,MchennaiM:Mbomba/M12 EMP_ID EMP_NAME CIT% DE&I'NATI(N &A"A % .......... ............. . .............. .............. ...........................

$BB $B) $BE

Aames pri/a ;amal

ban7alore calc-tta coimbatore

modleader mana7er proAlead

)BBBB NBBBB NQPBB

RESULT: Th-s the D?" commands are e6ec-ted and 3eri4ied5

TCL COMMANDS TRANSACTION CONTROL LANGUAGE


The DCL commands are: Commit ollbac; &a3e point

1. COMMIT: S"nta#: &?"+ set a-to commit on 2 &?"+ set a-to commit o44 2 &?"+commit 2 De$%r&'t&on: Commit command tells the DBM& to ma;e permanent chan7es made to temporar/ copies o4 the data -pdatin7 the permanent database tables to match the -pdated temporar/ copies5 (. ROLL BAC=: S"nta#: &?"+ rollbac; 2 De$%r&'t&on: ollbac; tells the DBM& to -ndo an/ chan7es made to the DBM& a4ter the most recent commit5

*. SA,E POINT: S"nta#: &?"+&a3epoint*name+2

De$%r&'t&on: &a3e point are li;e mar;ers to di3ide a 3er/ len7th/ transaction to smaller ones5 The/ are -sed to identi4/ a point in transaction to which we can later rollbac;5 Th-s sa3epoint is -sed in conA-nction with rollbac; to rollbac; portions o4 the c-rrent transaction5

PROGRAM TO LEARN TCL COMMANDS


ROLLBAC=: &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'%?T%_#AND E"EVE" MAO"EVE" ITEM ATE ............................ .......... .......... .......... .......... .......... $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N ! pen stationar/ DN NB DB P ! rows selected5 &?"+ delete 4rom item4ile where itemcodeK!2 $ row deleted5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N E rows delected5 &?"+ rollbac;2 ollbac; complete5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N ! pen stationar/ DN NB DB P

COMMIT: &?"+ delete 4rom item4ile where itemcodeK!2 $ row deleted5 &?"+ commit2 Commit complete5

&?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N &?"+ rollbac;2 ollbac; complete5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N SA,EPOINT: &?"+ sa3epoint s$2 &a3epoint created5 &?"+ -pdate item4ile set itemrateK)B where itemcodeKE2 $ row -pdated5 &?"+ sa3epoint s)2 &a3epoint created5 &?"+ -pdate item4ile set itemrateK$P where itemcodeK$2 $ row -pdated5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB $P ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ )B &?"+ rollbac; to s)2 ollbac; complete5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................ $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ )B &?"+ rollbac; to s$2 ollbac; complete5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .............. .............. .............. ............................

$ eraser stationar/ ) chain 4anc/ E tomato 3e7etable

$BB !B !PB

NB RD N!

)BB )BB $NQ

E )N N

RESULT: Th-s the DC" commands are e6ec-ted and 3eri4ied5

DCL COMMANDS DATA CONTROL LANGUAGE


The DCL commands are: 'rant e3o;e 1. GRANT: S"nta#: &?"+7rant *pri3ile7es+ on *table name+ to -ser 2 De$%r&'t&on: 'rant 7i3es speci4ic &?" statement access or indi3id-al data obAects to a -ser or a 7ro-p o4 -sers5 (. RE,O=E: S"nta#: &?"+ e3o;e *pri3ile7es+ on *tablename+ 4rom -ser 2 De$%r&'t&on: e3o;e remo3es speci4ic &?" statement access pre3io-sl/ 7ranted on indi3id-al database obAects 4rom a -ser or 7ro-p o4 -sers5

PREDICATES:
&?"+select94rom itemlist2 C(DE ........ $ ) E ITEM ........ Pen noteboo; Bat P ICE ......... )B5N QB5QN RR5RR

1. ALL

S"nta#:
&elect94rom table_name where col-mn_name +all,col-mn_3al-e1 E6ample: &<l+select 94rom itemlist where code+A"",I12 C(DE ITEM ........ ........ ) Noteboo; E Bat P ICE .......... QB5QN RR5RR

(. SOME:
S"nta#
&elect col-mn_name 4rom table_name where col_name)+some,selectcol-mn_name 4rom table_name where coll-m _nameEKH3al-eH12

E#am')e:
&?"+select item 4rom itemlist where code+some,select code 4rom itemlist where priceK)B5N12 ITEM ........ Noteboo; Bat

*. ANY
S"nta#:
&elect col-mn_name 4rom table name where col-mn_name+an/ ,select col-mn_name 4rom table_name where col-mn_nameKH3al-eH12

E#am')e:
&?"+select item 4rom itemlist where price+an/,select price 4rom itemlist where codeK)12 ITEM .......... Bat

+. LI=E
SYNTA>:
&elect94rom table_name ehere col-mn_name li;e,G3al-eH1

E#am')e:
&?"+select 94rom itemlist where item li;e,GPSH12 C(DE ITEM P ICE ........... ............ ............. $ PEN )B5N 999999999999999999999999999999999999999999999999999999999999999999999999999

(. ENTITY INTEGRITY CONSTRAINTS:

PRIMARY =EY: S"nta#:


Create table table _name ,4ield datat/pe1 constraints *label+ primar/ ;e/,col-mn_name12 &?"+ Create table note ,id n-mber,P1constraint 4lo not n-ll: n-m n-mber,P1primar/ ;e/12 Table created

&?"+ desc note2 NAME NU""@ T%PE .............. .............. ............. ID N(TNU"" NUMBE ,P1 NUM N(TNU"" NUMBE ,P1 &?"+ create table mic;/ ,id n-mber ,N1:name 3archar,P1 constraints mo-se primar/ ;e/,id:name112 Table created NAME ................ ID NAME NU""@ ................ T%PE ............... NUMBE ,N1 VA C#A ,P1

UNIQUE:
S"nta#:
Create table table _name ,4ield datat/pe1 constraints *label+ -ni<-e ,col-mn_name12 &?"+ create table Aeep ,id n-mber,N1 constraints 3an -ni<-e12 Table created &?"+ desc Aeep2 NAME& NU""@ ................ .................. ID &?"+insert into Aeep,Lid12 Enter the 3al-e 4or id:! $ row created &?"+ insert into Aeep,Lid12 Error at line$:J T%PE ................. NUMBE ,N1

REFERENCE INTEGRITY MODEL:


S"nta#:
Create table table _name , datat/pes FF551 constraints 4rom re4erences table_name ,col-mn_name12 &?"+ create table Aeep,id n-mber,N1constraint 4rom re4erences Aeep,id112 Table created &?"+desc Aeep2 NAME NU""@ ............ .............. ID T%PE ............. NUMBE ,N1

BUILT!IN FUNCTION
$5 'ro-p 4-nction or A77re7ate 4-nction:

S).No
$ ) E ! N P Q

F0n%t&on
AV' C(UNT MAO MIN &UM ATDDEV VA IANCE

De$%r&'t&on
Determines the A3era7e o4 the speci4ied 3al-es o4 col-mn: I7norin7 n-ll 3al-es5 Determines the total n-mber o4 3al-es o4 a speci4ied col-mn5 Determines the ma6im-m 3al-e o4 a speci4ied col-mn: i7norin7 n-ll 3al-es5 Determines the minim-m 3al-es o4 a speci4ied col-mn: i7norin7 n-ll 3al-es5 Determines the s-m o4 a speci4ied col-mn: i7norin7 n-ll 3al-es5 Determines the standard deri3ation o4 a speci4ied col-mn : i7norin7 n-ll 3al-es5 Determines the 3ariance o4 e6pression : i7norin7 n-ll 3al-es5

)5 Character T-nction:

S).No
$ ) E ! N P Q D R $B $$ $) $E $! $N $P

F0n%t&on
""( C(NCAT INIT CAP IN&T "EN'T# "(UE UPPE "PAD PAD "T IM T IM &(UNDEO &UB&T C# A&CII T AN&"ATE EP"ACE

De$%r&'t&on
Concatenates two strin7 to7ether chan7es the 4irst letter o4 a word or series o4 words into -pper case5 Tind the location o4 character in a strin7 otherwise ret-rn B5 Tind the "ocation o4 character in a strin7 otherwise ret-rn B5 et-rns the len7th o4 a strin75 Con3erts e3er/ letter in a strin7 to lower case5 Con3erts e3er/ letter in a strin7 to -pper case5 Ma;es a strin7 a certain len7th b/ a addin7 a certain set o4 character to the le4t5 Ma;es a strin7 a certain len7th b/ a addin7 a certain set o4 character to the i7ht5 Trim all the occ-rrence o4 an/ one o4 a set o4 character o4 the "e4t side o4 strin75 Trim all the occ-rrence o4 an/ one o4 a set o4 character o4 the i7ht side o4 strin75 Tinds words that so-nd li;e e6amples5 Clip o-t a piece o4 a strin75 et-rn the character o4 the speci4ied A&CII 3al-es5 et-rn the A&CII 3al-es o4 the speci4ied character5 eplace the character b/ character5 eplace the speci4ied strin7 or character b/ the e6istin7 strin7 or character i4 that strin7 in 4o-nd case sensiti3e5

E5 N-mber T-nction:

S).No
$ ) E ! N P Q D R $B $$ $) $E

F0n%t&on
AB& CE"" T"(( &A T P(UE &I'N T UNC (UND EOP M(D "N "(" V&IVE

De$%r&'t&on
et-rn absol-te 3al-es5 &mallest inte7er lar7e than or e<-al to 3al-e5 "ar7est inte7er smaller than or e<-al to 3al-e5 et-rns s<-ares not o4 the speci4ied b/ the n-mber5 et-rn power speci4ied b/ n-mber5 et-rn.$ o4 the n-mber is ne7ati3e2 et-rn $ i4 the n-mber is positi3e and ret-rn B i4 the n-mber is B5 Tr-ncates the n-mber a4ter the decimal dependin7 on the speci4ied inte7er5 o-nd the e6pression to the speci4ied n-mber o4 decimals5 et-rns e raised to n power5 et-rn mod-le 3al-e5 Nate-al "o7arithm 3al-es5 Base $B "o7-ith 3al-e5 &torade si0e o4 a 3al-e5

$! $N

' EATE&T "EA&T

'reatest 3al-e o4 a list5 "east 3al-e o4 a llist5

!5 Date T-nction:

S).No
$ ) E ! N P Q

F0n%t&on
&%& DATE ADD_M(NT#& NEOT_DA% CA&E_DA% M(NT#&_BETUEEN (UND T UNC

De$%r&'t&on
et-rns s/stem date Add or s-bstracts months to or 4rom a date: ret-rn date as res-lt5 et-rns the date o4 ne6t speci4ied da/ o4 the wee; a4ter the date5 et-rns the date o4 the last da/ o4 the months speci4ied5 et-rns n-mber o4 months between dates5 o-nd the date d b/ the speci4ied 4ormat: i4 4ormat is not speci4ied it de4a-lts to GDDH5 Uhich date to the neatest da/5 o-nds the date d tr-ncates to the -nit speci4ied b/ omitted is de4a-lts to GDPH which tr-ncates to the nearest da/5

N5 Con3ertion T-nction:

S).No
$ ) E !

F0n%t&on
T(_C#A T(_DATE DEC(DE T(_NUMBE

De$%r&'t&on
Con3ert the dateGdH to character 4ormat G4H5 Con3ert the dateGdH to date 4ormat G4H5 ecords the speci4ied date to another representation5 Con3ert the character to n-mber5

C3ARACTER FUNCTION:
&?"+ select 9 4rom st-d2 (""N( NAME DEPT MA W& .......... ........................... .............. .......... E mohan cse NB ! parandha bme QD N raAan cse QD $ ;-maran cse RB ) midh-n ece DB &?"+ select -pper,name1 4rom st-d2 UPPE ,NAME1 ............... M(#AN PA AND#A ACAN WUMA AN MID#UN &?"+ select lower,name1 4rom st-d2 "(UE ,NAME1 ............... mohan parandha raAan ;-maran

midh-n

&?"+ select initcap,name1 4rom st-d2 INITCAP,NAME1 ............... Mohan Parandha aAan W-maran Midh-n &?"+ select s-bstr,M7iriAaM:$:!1 4rom d-al2 &UB& .... 7iri &?"+ select ltrim,MwelcomeM:MwelM1 4rom d-al2 "T I .... come &?"+ select rtrim,MwelcomeM:McomeM1 4rom d-al2 T ... wel &?"+ select lpad,MwelcomeM:$E:MXM1 4rom d-al2 "PAD,MUE"C(ME ............. XXXXXXwelcome &?"+ select rpad,MwelcomeM:$E:MXM1 4rom d-al2 PAD,MUE"C(ME ............. welcomeXXXXXX &?"+ select name 4rom st-d where name li;e MmSM2 NAME ............... mohan midh-n &?"+ select replace,MAac; Aill Ao/M:MAM:MbM1 4rom d-al2 EP"ACE,MCACW ............. bac; bill bo/ &?"+ select translate,MAac; Aall Ao/M:MAaM:MbM1 4rom d-al2 T AN&"ATE,M ...........

bc; bll bo/

DATE FUNCTION:
&?"+ select add_months,M)N.dec.BQM:!1 4rom d-al2 ADD_M(NT# ......... )N.AP .BD &?"+ select last_da/,M)N.dec.BQM1 4rom d-al2 "A&T_DA%, ......... E$.DEC.BQ &?"+ select months_between,M$N.dec.BQM:M$E.a-7.BQM1 4rom d-al2 M(NT#&_BETUEEN,M$N.DEC.BQM:M$E.AU'.BQM1 ....................................... !5BP!N$P$E &?"+ select ne6t_da/,M$.A-l.BQM:M4rida/M1 4rom d-al2 NEOT_DA%, ......... BP.CU".BQ &?"+ select 7reatest,M)).ma/.BQM:M)).dec.BQM1 4rom d-al2 ' EATE&T, ......... )).ma/.BQ

AGGREGATE FUNCTION:
&?"+ select a37,mar;s1 4rom st-d2 AV',MA W&1 .......... QN5) &?"+ select min,mar;s1 4rom st-d2 MIN,MA W&1 .......... NB &?"+ select ma6,mar;s1 4rom st-d2 MAO,MA W&1 .......... RB &?"+ select co-nt,mar;s1 4rom st-d2 C(UNT,MA W&1 ............ N

&?"+ select s-m,mar;s1 4rom st-d2 &UM,MA W&1 .......... EQP &?"+ select stdde3,$QNN1 4rom d-al2 &TDDEV,$QNN1 ............ B &?"+ select 3ariance,$QNN1 4rom d-al2 VA IANCE,$QNN1 .............. B

NUMERIC FUNCTIONS:
&?"+ &E"ECT AB&,.$N1 T (M DUA"2 AB&,.$N1 .......... $N &?"+ select abs,.$N1 4rom d-al2 AB&,.$N1 .......... $N &?"+ select power,):E1 4rom d-al2 P(UE ,):E1 .......... D &?"+ select ro-nd,$DR5RRRR:)1 4rom d-al2 (UND,$DR5RRRR:)1 ................. $RB &?"+ select tr-nc,$DR5RRRR:)1 4rom d-al2 T UNC,$DR5RRRR:)1 ................. $DR5RR &?"+ select mod,$B:E1 4rom d-al2 M(D,$B:E1 .......... $ &?"+ select si7n,$P1 4rom d-al2 &I'N,$P1 .......... $ &?"+ select si7n,.$P1 4rom d-al2 &I'N,.$P1 .......... .$ &?"+ select sin,!N1 4rom d-al2 &IN,!N1 .......... 5DNBRBEN)N

&?"+ select cos,!N1 4rom d-al2 C(&,!N1 .......... 5N)NE)$RDR &?"+ select sinh,PB1 4rom d-al2 &IN#,PB1 .......... N5Q$BBEY)N &?"+ select cosh,PB1 4rom d-al2 C(&#,PB1 .......... N5Q$BBEY)N &?"+ select ceil,$E!5QD1 4rom d-al2 CEI",$E!5QD1 ............ $EN &?"+ select 4loor,$E!5QD1 4rom d-al2 T"(( ,$E!5QD1 ............. $E! &?"+ select ln,EN1 4rom d-al2 "N,EN1 .......... E5NNNE!DBP &?"+ select lo7,$B:$BBB1 4rom d-al2 "(',$B:$BBB1 ............ E &?"+ select s<rt,)N1 4rom d-al2 &? T,)N1 .......... N

O'erator$
RELATIONAL?COMPERISON OPERATIONS
K + * +K *K *+ ZK

LOGICAL OPERATORS
AND ( N(T

SPECIAL OPERATORS
In Between "i;e Is An/ All The

ARIT3METIC OPERATORS
Y . 9 8

SET OPERATORS
Union Union all Intersect Min-s

Set O'erator$
1. Un&on
De$%r&'t&on:
M-ltiple <-eries can be p-t to7ether and their o-tp-t combined -sin7 -nion cla-se with d-plication: the -nion cla-se mer7es the o-tp-t o4 ) or more <-eries into sin7le set o4 rows and col-mns5 &?"+ select c_name 4rom borrower -nion select c_name 4rom depositor2 C_NAME .......... adams c-rr/ ha/es Aac;son Aohnson Aones lindsa/ smith

(. Un&on A))
De$%r&'t&on:
M-ltiple <-eries can be p-t to7ether and their o-tp-t combined -sin7 -nion all cla-se with d-plicate5 &?"+ select c_name 4rom borrower -nion all select c_name 4rom depositor2 C_NAME .......... adams c-rr/ ha/es Aac;son Aones smith smith willams ha/es Aohnson

Aohnson Aones lindsa/ smith t-rner $N rows selected5

*. Inter$e%t&on
De$%r&'t&on:
M-ltiple <-eries can be p-t to7ether and their o-tp-t combine -sin7 -nion cla-se intersect cla-se o-tp-t (nl/ rows prod-ced b/ both the <-eries intersected5 &?"+ select c_name 4rom borrower intersect select c_name 4rom depositor2 C_NAME .......... ha/es Aones smith

+. M&n0$
De$%r&'t&on:
M-ltiple <-eries can be p-t to7ether and their o-tp-t can be combines -sin7 min-s cla-ses5 The min-s Cla-se o-tp-t the rows prod-ced b/ both the 4irst <-er/: a4ter 4ilterin7 the rows retrie3ed b/ second <-er/5 &?"+ select c_name 4rom borrower min-s select c_name 4rom depositor2 C_NAME .......... adams c-rr/ Aac;son willams

@OINS AND NESTED QUERIES


AIM:
To st-d/ abo-t 3ario-s Aoins and nested <-eries5

@OINS:
Coins <-eries are -sed to retrie3e data 4rom m-ltiple tables5

TYPES OF @OINS:
$5 )5 E5 E?UI C(IN CA TE&IAN C(IN (UTE C(IN I'#T (UTE C(IN "ETT (UTE C(IN

TABLE STRUCUUTRE:

SQL+ select 9 4rom empl2

EMP_ID ............ $B )B EB !B NB PB P rows selected5

EMP_NAME .................. Allwin E3elin Ces-s Comp-ter Poornima Dra3id

CIT% &A"A % .......... ............ Pd/ NBBBB Chennai PNBBB Uorld NBBBBB Chennai !!BBB Pd/ NBBBB Pd/ NBBBB

SQL+ select 9 4rom dept$2

DEPT_N( .............. EB PB NB )B

EMP_NAME ................. Ces-s Dra3id Poornima CPU

"(CATI(N ................ Uorld Chennai Delhi Compa<

SQL+ select 9 4rom 7rade2

' ADE "(UE&T_&A"A % ........... ........................... $ QBB ) $)B$ E $!B$ ! )BB$ N $BBBB P NBBBB P rows selected5

#I'#E&T_&A"A % ........................... $)BB $!BB )BBB NBBB NBBBB NBBB$

EA0& @o&n:!
De$%r&'t&on:!

E<-i Aoins are done b/ e<-atin7 tables based on a criteria5It -ses GKH s/mbol5
1BL&$t t6e em')o"ee eta&)$ -&t6 t6e&r e'artment name an )o%at&on.

SQL+

select location:salar/:dept$5dept_no empl5emp_nameKdept$5emp_name2 "(CATI(N ................ Chennai Uorld Delhi Carte$&an @o&n:! &A"A % ............ NBBBB NBBBBB NBBBB DEPT_N( ............. PB EB NB

4rom

empl:dept$

where

Cartesian Aoin is all combination o4 rows 4rom di44erent tables5


(BL&$t a)) t6e &;;erent 'o$$&C)e ro-$ ;rom em' D e't taC)e$.
SQL+ select e5emp_name:e5salar/:d5emp_name:d5location 4rom empl e:dept$ d2

EMP_NAME ............... Allwin E3elin Ces-s Comp-ter Poornima Dra3id Allwin E3elin Ces-s Comp-ter Poornima

&A"A % ............ NBBBB PNBBB NBBBBB !!BBB NBBBB NBBBB NBBBB PNBBB NBBBBB !!BBB NBBBB

EMP_NAME ................. Ces-s Ces-s Ces-s Ces-s Ces-s Ces-s Dra3id Dra3id Dra3id Dra3id Dra3id

"(CATI(N ............... Uorld Uorld Uorld Uorld Uorld Uorld Chennai Chennai Chennai Chennai Chennai

EMP_NAME ............... Dra3id Allwin E3elin Ces-s Comp-ter Poornima Dra3id Allwin

&A"A % ............ NBBBB NBBBB PNBBB NBBBBB !!BBB NBBBB NBBBB NBBBB

EMP_NAME .................. Dra3id Poornima Poornima Poornima Poornima Poornima Poornima CPU

"(CATI(N ............... Chennai Delhi Delhi Delhi Delhi Delhi Delhi Compa<

E3elin Ces-s Comp-ter EMP_NAME ............... Poornima Dra3id )! rows selected5 Non EA0& @o&n:!

PNBBB NBBBBB !!BBB &A"A % ............ NBBBB NBBBB

CPU CPU CPU EMP_NAME ................. CPU CPU

Compa< Compa< Compa< "(CATI(N ............... Compa< Compa<

Non e<-i Aoins are other than GKH operator i4 Aoin is 4ormed -sin7 an/ one o4 the relational operators,*:+:ZK:*+:+K:*K15
*B L&$t t6e ename D 5ra e o; t6e em')o"ee$ e'rn &n5 on t6e&r $a)ar".
SQL+ select e5emp_name:757rade 4rom empl e:7rade 7 where e5salar/+K75lowest_salar/

and e5salar/*K75hi7hest_salar/2 EMP_NAME ................. Allwin Comp-ter Poornima Dra3id Allwin Poornima Dra3id Q rows selected5 O0ter @o&n:!
De$%r&'t&on:!

' ADE .......... N N N N P P P

(-ter Aoins retrie3es the row ret-rned b/ e<-i Aoin as well as the row that do not match an/ row 4rom other tables5 R&56t O0ter @o&n:!
+Ba.L&$t t6e name: e'artment D %onta&n no em')o"ee$. e'tno ;rom em': e't taC)e$ e4en &; t6e e'artment

SQL+

select e5emp_name:d5emp_name:d5dept_no e5emp_nameKd5emp_name,Y12 EMP_NAME ................. Allwin Comp-ter Dra3id E3elin Ces-s Poornima P rows selected5
+BC.L&$t t6e a)) t6e ;&e) em')o"ee$.

4rom empl e:dept$ d where

EMP_NAME .................. Dra3id Ces-s Poornima

DEPT_N( .............. PB EB NB

;rom em': e't taC)e$ e4en &; t6e

e'artment

%onta&n no

SQL+ select 9 4rom empl nat-ral ri7ht o-ter Aoin dept$2

EMP_NAME EMP_ID CIT% &A"A % DEPT_N( "(CATI(N ................. ............ .......... ............ ............... ................ Ces-s EB Uorld NBBBBB EB Uorld Poornima NB Pd/ NBBBB NB Delhi Dra3id PB Pd/ NBBBB PB Chennai CPU )B Compa<

Le;t O0ter @o&n:!


SQL+

select e5emp_name:d5emp_name:d5dept_no e5emp_name,Y1Kd5emp_name2 EMP_NAME ................. Dra3id Ces-s Poornima EMP_NAME ................. CPU Dra3id Ces-s Poornima DEPT_N( .............. )B PB EB NB

4rom empl e:dept$ d where

SQL7 select 9 4rom empl nat-ral le4t o-ter Aoin dept$2

EMP_NAME EMP_ID CIT% &A"A % DEPT_N( "(CATI(N ................. ............ .......... ............ ............... ................ Ces-s EB Uorld NBBBBB EB Uorld Dra3id PB Pd/ NBBBB PB Chennai Poornima NB Pd/ NBBBB NB Delhi Comp-ter !B Chennai !!BBB Allwin $B Pd/ NBBBB E3elin )B Chennai PNBBB P rows selected5 PL?SQL PROGRAMS
1. ADDITION OF T2O NUMBERS

AIM:
To write the P"[&?" pro7ram to 4ind the addition o4 two n-mbers5

PROGRAM
declare 6 inte7er2 / inte7er2 0 inte7er2 be7in 6:KL62 /:KL/2 0:K6Y/2 dbms_o-tp-t5p-t_line,MThe &-m o4 two n-mber is KM\\012 end2

OUTPUT :
&?"+8 &?"+ set ser3ero-tp-t on2 Enter 3al-e 4or 6: $B old P: 6:KL62 new P: 6:K$B2 Enter 3al-e 4or /: )B old Q: /:KL/2 new Q: /:K)B2 The &-m o4 two n-mber is KEB P"8&?" proced-re s-ccess4-ll/ completed5

RESULT:
Th-s the P"[&?" pro7ram to 4ind the addition o4 two n-mbers are e6ec-ted and 3eri4ied5

FACTORIAL OF A NUMBER
AIM: To write the P"8&?" pro7ram to 4ind the 4actorial o4 a n-mber5 PROGRAM: declare 4 n-mber:K$2 i n-mber2 n n-mber:KLn2 be7in 4or i in $55n loop 4:K49i2 end loop2 dbms_o-tp-t5p-t_line,MThe 4actorial o4 a 7i3en no is:M\\412 end2 SAMPLE INPUT OUTPUT : &?"+ set ser3ero-tp-t on2 &?"+8 Enter 3al-e 4or n: P old !: n n-mber:KLn2 new !: n n-mber:KP2 The 4actorial o4 a 7i3en no is:Q)B P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" pro7ram to 4ind the 4actorial o4 a n-mber is e6ec-ted and 3eri4ied5

PALINDROME
AIM: To write the P"8&?" pro7ram to chec; whether the 7i3en strin7 is a Palindrome5 PROGRAM: declare len n-mber2 a inte7er2 str$ 3archar,$B1:KMLstr$M2 str) 3archar,$B12 be7in len:Klen7th,str$12 a:Klen2 4or i in $55a loop str):Kstr)\\s-bstr,str$:len:$12 len:Klen.$2 end loop2 i4 ,str$Kstr)1 then dbms_o-tp-t5p-t_line,str$ \\ M else dbms_o-tp-t5p-t_line,str$ \\ M end i42 end2 SAMPLE INPUT OUTPUT : &?"+ set ser3ero-tp-t on2 &?"+8 Enter 3al-e 4or str$: liril old !: str$ 3archar,$B1:KMLstr$M2 new !: str$ 3archar,$B1:KMlirilM2 liril is a palindrome P"8&?" proced-re s-ccess4-ll/ completed5

is a palindromeM12 not a palindromeM12

&?"+ 8 Enter 3al-e 4or str$: 4aith old !: str$ 3archar,$B1:KMLstr$M2 new !: str$ 3archar,$B1:KM4aithM2 4aith not a palindrome P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" pro7ram to chec; the 7i3en strin7 is a Palindrome or not is e6ec-ted and 3eri4ied5

FIBONACCI
AIM: To write the P"8&?" pro7ram to 4ind the Tibonacci o4 a 7i3en n-mber5 PROGRAM: declare i n-mber2 c n-mber2 n n-mber:KLn2 a n-mber:K.$2 b n-mber:K$2 be7in 4or i in $55n loop c:KaYb2 dbms_o-tp-t5p-t_line,c12 a:Kb2 b:Kc2 end loop2 end2 SAMPLE INPUT OUTPUT : &?"+ set ser3ero-tp-t on2 &?"+8 Enter 3al-e 4or n: N old !: n n-mber:KLn2 new !: n n-mber:KN2 B $ $ ) E P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" pro7ram to 4ind the Tibonacci o4 a 7i3en n-mber is e6ec-ted and 3eri4ied5

SUM OF SERIES
AIM: To write the P"8&?" pro7ram to 4ind the &-m o4 series5 PROGRAM: declare n n-mber:KLn2 i n-mber2 be7in i:Kn9,nY$12 n:Ki8)2 dbms_o-tp-t5p-t_line,MThe s-m o4 series is:M\\n12 end2 ,or1 declare n n-mber2 s n-mber2 i n-mber2 be7in n:KLn2 s:KB2 4or i in $55n loop s:KsYi2 end loop2 dbms_o-tp-t5p-t_line,Ms-mKM\\s12 end2 SAMPLE INPUT OUTPUT : &?"+ set ser3ero-tp-t on2 &?"+8 Enter 3al-e 4or n: N old ): n n-mber:KLn2 new ): n n-mber:KN2 The s-m o4 series is:$N

P"8&?" proced-re s-ccess4-ll/ completed5 RESULT: Th-s the P"8&?" pro7ram to 4ind the &-m o4 series is e6ec-ted and 3eri4ied5 TRIGGERS AIM: To write a P"8&?" pro7ram -sin7 tri77ers to replicate the record5 TABLE STRUCTURE 1: TaC)e name: tr&511 FIELD NAME ("" N( NAME MA W$ MA W) MA WE DATA TYPE NUME IC A"P#ANUME IC NUME IC NUME IC NUME IC SIZE E $B E E E

&?"+ create table tri7$$,rlno n-mber,E1:name 3archar,$B1:mar;$ n-mber,E1:mar;) n-mber,E1:mar;E n-mber,E112 Table created5 TABLE STRUCTURE 1: TaC)e name: tr&51( FIELD NAME ("" N( NAME MA W$ MA W) MA WE DATA TYPE NUME IC A"P#ANUME IC NUME IC NUME IC NUME IC SIZE E $B E E E

&?"+ create table tri7$),rlno n-mber,E1:name 3archar,$B1:mar;$ n-mber,E1:mar;) n-mber,E1:mar;E n-mber,E112 Table created5

PROGRAM: create or replace tri77er cc a4ter insert or delete or -pdate on tri7$$

4or each row be7in i4 insertin7 then insert into tri7$) 3al-es,:new5rlno::new5name::new5mar;$::new5mar;)::new5mar;E12 elsi4 deletin7 then delete 4rom tri7$) where rlnoK:old5rlno2 else -pdate tri7$) set mar;$K:new5mar;$:mar;)K:new5mar;):mar;EK:new5mar;E where rlnoK:old5rlno2 end i42 end2 SAMPLE INPUT OUTPUT: &?"+ 8 Tri77er created5 &?"+ select 9 4rom tri7$$2 "N( NAME MA W$ MA W) MA WE .......... .......... .......... .......................... .......... ) ss QD QP ND E tt RD QP N! ! -QP NP EN &?"+ select 9 4rom tri7$)2 "N( NAME MA W$ MA W) MA WE .......... ...... .... ......................... .......... .......... ) ss QD QP ND E tt RD QP N! ! -QP NP EN

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 tri77ers is e6ec-ted and 3eri4ied5 TRIGGERS AIM: To write a P"8&?" pro7ram to displa/ the old and new 3al-es o4 a record a4ter -pdatin7 -sin7 tri77ers5 PROGRAM: create or replace tri77er 666 a4ter -pdate on si3a 4or each row be7in dbms_o-tp-t5p-t_line,Mmar;$ old 3al-e:M\\:old5mar;$12 dbms_o-tp-t5p-t_line,Mmar;) new 3al-e:M\\:new5mar;$12 dbms_o-tp-t5p-t_line,Mmar;) old 3al-e:M\\:old5mar;)12 dbms_o-tp-t5p-t_line,Mmar;) new 3al-e:M\\:new5mar;)12 dbms_o-tp-t5p-t_line,Mmar;E old 3al-e:M\\:old5mar;E12 dbms_o-tp-t5p-t_line,Mmar;E new 3al-e:M\\:new5mar;E12 end2 SAMPLE INPUT OUTPUT: &?"+8 Tri77er created5 &?"+ -pdate si3a set mar;$KRB:mar;)KDR:mar;EKRR where rlnoK)2 mar;$ old 3al-e:RR mar;) new 3al-e:RB mar;) old 3al-e:QD mar;) new 3al-e:DR mar;E old 3al-e:PQ mar;E new 3al-e:RR $ row -pdated5

&?"+ select 9 4rom si3a2

"N( NAME MA W$ MA W) MA WE .......................... ..... .......... .......... .......... $ ram/a $BB RD DQ ) si3a RR QD PQ E san7 QN DQ PN &?"+ select 9 4rom si3a2 "N( NAME MA W$ MA W) MA WE .......... ..................... .......... .......... .......... $ ram/a $BB RD DQ ) si3a RB DR RR E san7 QN DQ PN

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 tri77ers is e6ec-ted and 3eri4ied5

TRIGGERS AIM: To write a P"8&?" pro7ram to restrict the entries into the table -sin7 tri77ers5 PROGRAM: create or replace tri77er tri77n a4ter insert or delete or -pdate on si3a 4or each row be7in i4 insertin7 then raise_application_error,.)BBP:Minsertion not possibleM12 elsi4 deletin7 then raise_application_error,.)BBQ:Mdeletion is not possibleM12 else raise_application_error,.)BBD:M-pdation is not possibleM12 end i42 end2 &?"+ select 9 4rom si3a2 "N( NAME MA W$ MA W) MA WE .......... ..... .......... .......... ......................... $ ram/a $BB RD DQ ) si3a RB DR RR E san7 RB DR RR &?"+ insert into si3a 3al-es,!:Mpri/aM:NP:PN:PQ12 $ row created5

&?"+ select 9 4rom si3a2 "N( NAME MA W$ MA W) MA WE

..................... ...... ..... .......... .......... .......... $ ram/a $BB RD DQ ) si3a RB DR RR E san7 RB DR RR ! pri/a NP PN PQ &?"+ 8 Tri77er created5 &?"+ insert into si3a 3al-es,N:M;a3iM:QD:DQ:PN12 insert into si3a 3al-es,N:M;a3iM:QD:DQ:PN1 9 E ( at line $: ( A.)$BBB: error n-mber ar7-ment to raise_application_error o4 .)BBP is o-t o4 ran7e ( A.BPN$): at ]&C(TT5T I''N]: line E ( A.B!BDD: error d-rin7 e6ec-tion o4 tri77er M&C(TT5T I''NM &?"+ delete 4rom si3a where rlnoK!2 delete 4rom si3a where rlnoK! 9 E ( at line $: ( A.)$BBB: error n-mber ar7-ment to raise_application_error o4 .)BBQ is o-t o4 ran7e ( A.BPN$): at ]&C(TT5T I''N]: line N ( A.B!BDD: error d-rin7 e6ec-tion o4 tri77er M&C(TT5T I''NM &?"+ -pdate si3a set mar;$KRR where rlnoK!2 -pdate si3a set mar;$KRR where rlnoK! 9 E ( at line $: ( A.)$BBB: error n-mber ar7-ment to raise_application_error o4 .)BBD is o-t o4 ran7e ( A.BPN$): at ]&C(TT5T I''N]: line Q ( A.B!BDD: error d-rin7 e6ec-tion o4 tri77er M&C(TT5T I''NM

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 tri77ers is e6ec-ted and 3eri4ied5

E>CEPTION 3ANDLING
Error condition in P"8&?" is termed as an e6ception5 There are two t/pes o4 E6ception5 The/ are Prede4ined E6ception User.de4ined E6ception An E6ception is raised when an error occ-rs5 In case o4 an error: normal e6ec-tion stops and the control is immediatel/ trans4erred to the e6ception handlin7 part o4 the P"[&?" bloc;5 Prede4ined E6ception is raised a-tomaticall/ b/ the s/stem d-rin7 r-n time: whereas -ser.de4ined e6ceptions are raised e6plicitl/ -sin7 AI&E statements5 PREDEFINED E>CEPTION: S"nta#: Be7in &e<-ence_o4_statements2 E6ception Uhen *e6ception_name+ then &e<-ence_o4_statements2 Uhen others then 89 the last e6ception in the e6ception handler98 &e<-ence_o4_statements2 End2 USER!DEFINED E>CEPTION: User.de4ined e6ception sho-ld be declared onl/ in the declarati3e part o4 the P"8&?" bloc;5 S"nta#: *e6ception_name+ e6ception2 The &/nta6 4or a raise statement is as 4ollows5 raise *e6ception_name+2

USER!DEFINED E>CEPTION
AIM: To write a -serde4ined e6ception handlin7 pro7ram -sin7 P"8&?"5 PROGRAM: declare co n-mber2 e6ceeds_3al-e e6ception2 be7in select co-nt,91 into co 4rom emplo/e2 i4 co *N then insert into emplo/e 3al-es ,Lempno:MLempnameM:MLempstM:Lempsal12 else raise e6ceeds_3al-e2 end i42 e6ception when e6ceeds_3al-e then dbms_o-tp-t5p-t_line,Mrows will not be insertedM12 end2 SAMPLE INPUT OUTPUT: &?"+ select 9 4rom emplo/e2 EMPN( EMPNAME EMP&T &A"E % .......... ......................... .......... .......... $ radha leader )BBBB ) ;a3i mana7er !BBBB E malini anal/st $!BBB ! arthi admin )$BBB &?"+ 8 Enter 3al-e 4or empno: N Enter 3al-e 4or empname: raAeswari Enter 3al-e 4or empst: so4tware Enter 3al-e 4or empsal: )NBBB old Q: insert into emplo/e 3al-es ,Lempno:MLempnameM:MLempstM:Lempsal12 new Q: insert into emplo/e 3al-es ,N:MraAeswariM:Mso4twareM:)NBBB12 P"8&?" proced-re s-ccess4-ll/ completed5

&?"+ 8 Enter 3al-e 4or empno: P Enter 3al-e 4or empname: madha3an Enter 3al-e 4or empst: leader Enter 3al-e 4or empsal: )!BBB old Q: insert into emplo/e 3al-es ,Lempno:MLempnameM:MLempstM:Lempsal12 new Q: insert into emplo/e 3al-es ,P:Mmadha3anM:MleaderM:)!BBB12 rows will not be inserted P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom emplo/e2 EMPN( EMPNAME EMP&T &A"E % .......... ......................... .......... ...................... $ radha leader )BBBB ) ;a3i mana7er !BBBB E malini anal/st $!BBB ! arthi admin )$BBB N raAeswari so4tware )NBBB

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 -ser.de4ined e6ception handler is e6ec-ted and 3eri4ied5

PREDEFINED E>CEPTION
AIM: To write a prede4ined e6ception handlin7 pro7ram -sin7 P"8&?" 5 PROGRAM: declare empid n-mber,N12 emname 3archar,NB12 be7in empid:KLempid2

select empname into emname 4rom emplo/e where empnoKempid2 dbms_o-tp-t5p-t_line,MThe emplo/e name is:M\\emname12 e6ception when no_data_4o-nd then dbms_o-tp-t5p-t_line,Mdata not 4o-ndM12 end2 SAMPLE INPUT OUTPUT : Enter 3al-e 4or empid: $ old N: empid:KLempid2 new N: empid:K$2 The emplo/e name is:radha P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ 8 Enter 3al-e 4or empid: N old N: empid:KLempid2 new N: empid:KN2 data not 4o-nd P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 pre.de4ined e6ception handler is e6ec-ted and 3eri4ied5

CURSORS
AIM: Create a P"8&?" bloc; that deletes st-dentHs records whose department is C&E and displa/ the n-mber o4 records deleted and the remainin7 n-mber o4 records5 PROGRAM: declare c-rsor c is select 9 4rom st-ddd cse2 a cS rowt/pe2 n n-mber:KB2 be7in open c2 loop 4etch c into a2 e6it when cS not4o-nd2 i4 a5deptKMcseM then delete 4rom st-ddd where deptKMcseM2 n:KnY$2 end i42 end loop2 dbms_o-tp-t5p-t_line,MDeleted record M\\n12 dbms_o-tp-t5p-t_line,M emainin7 records M\\,cS rowco-nt.n112 close c2 commit2 end2

SAMPLE INPUT OUTPUT: &?"+ 8 Deleted record ) emainin7 records E P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom st-ddd2 "N( NAME DEPT .......... ........ ...... $ abhilash cse ) ;amala eee E mareesh bme ! samson cse N saran/a it Q rows selected5 &?"+ select 9 4rom st-ddd2 "N( NAME DEPT .......... ........ ...... ) ;amala eee E mareesh bme N saran/a it

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 c-rsor is e6ec-ted and 3eri4ied5

CURSORS
AIM: Create a P"8&?" bloc; to determine the top N scores 4rom the st-dent table and to insert these records into a new table5 PROGRAM: declare c-rsor c is select 9 4rom st-dddd order b/ total desc2 a st-dddd S rowt/pe2 n n-mber:KB2 be7in open c2 loop 4etch c into a2 e6it when cS not4o-nd or cS rowco-nt+N2 insert into detail$ 3al-es,a5rollno:a5name:a5dept:a5total12 end loop2 close c2 commit2 end2 SAMPLE INPUT OUTPUT: &?"+8 P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom st-dddd2 (""N( NAME DEPT T(TA" .......... ........ ............................. $ s3 cse )DQ ) archcse )DR E re;;a cse )RB ! aarthi cse )DB N thamarai it EBB P tharani bme $NB Q ranAani cse )BB Q rows selected5 &?"+ select 9 4rom detail$2 (""N( NAME DEPT T(TA"

.......... ........ ...... .......... N thamarai it EBB E re;;a cse )RB ) archcse )DR $ s3 cse )DQ ! aarthi cse )DB

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 c-rsor is e6ec-ted and 3eri4ied5 CURSORS AIM: Create a P"8&?" bloc; to -pdate the total and 7rade o4 the st-dent table b/ comparin7 mar;s in the indi3id-al s-bAect5 PROGRAM: declare c-rsor c is select 9 4rom st-ddd$2 a cS rowt/pe2

tot n-mber2 7 char2 be7in open c2 loop 4etch c into a2 e6it when cS not4o-nd2 tot:Ka5m$Ya5m)Ya5mE2 i4 a5m$+NB and a5m)+NB and a5mE+NB then 7:KM#M2 else 7:KMTM2 end i42 -pdate st-ddd) set totalKtot:7radeK7 where rollnoKa5rollno2 end loop2 commit2 close c2 end2 SAMPLE INPUT OUTPUT: &?"+ 8 P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom st-ddd$2 (""N( NAME M$ M) ME ........................... ........ .......... .......... .......... $ s3s PB PQ PQ ) re;;a NP PQ QD E archQD !N EB &?"+ alter table st-ddd$ add,total n-mber:7rade 3archar,P112 Table altered5 &?"+ desc st-ddd$2 Name N-ll@ T/pe ......................................... ........ ............................ (""N( NUMBE ,Q1 NAME VA C#A ),D1 M$ NUMBE ,D1

M) ME T(TA" ' ADE &?"+ select 9 4rom st-ddd$2

NUMBE ,D1 NUMBE ,D1 NUMBE VA C#A ),P1

(""N( NAME M$ M) ME T(TA" ' ADE .......... ........ .......... ....................... .......... .......... ...... $ s3s PB PQ PQ $R! # ) re;;a NP PQ QD )B$ # E archQD !N EB $NE T RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 c-rsor is e6ec-ted and 3eri4ied5

A T-nction is a s-bpro7ram that comp-tes a 3al-e5 The s/nta6 4or creatin7 a 4-nction is 7i3en below5 Create or replace 4-nction * 4-nction_name + I ar7-ment J ret-rn datat/pe is ,local declaration1 Be7in ,e6ec-table statements1 IE6ceptionJ ,e6ception handlers1 end2

AIM: To write a P"8&?" bloc; -sin7 4-nction to chec; whether the <-antit/ on hand and reorder le3el e6ceeded the ma6im-m le3el5 PROGRAM: create or replace 4-nction items,it 3archar)1 ret-rn n-mber is ar7s n-mber2 <t/hand n-mber2 rele3el n-mber2 ma6le3el n-mber2 be7in select <_hand:re_le3el:ma6_le3el into <t/hand:rele3el:ma6le3el 4rom item4ile where icodeKit2 i4,<t/handYrele3el1+ma6le3el then ar7s:Kma6le3el2 ret-rn ar7s2 else ar7s:K,<t/handYrele3el12 ret-rn ar7s2 end i42 end2 &?"+8 T-nction created5 &?"+ declare

a 3archar),N12 b n-mber2 be7in a:KMLaM2 b:Kitems,a12 dbms_o-tp-t5p-t_line,Mthe 3al-es ret-rned is M \\ b12 end2 SAMPLE INPUT OUTPUT: &?"+8 Enter 3al-e 4or a: i)B$ old N: a:KMLaM2 new N: a:KMi)B$M2 the 3al-es ret-rned is RB P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom item4ile2 IC(DE IDE&C P_CAT'( % ?_#AND E_"EVE" MAO_"EVE" I_ ATE .......... .......... ............... .......... .......... .......... ............ ....... ........... i)B$ i)B) i)B! i)BN i)BE n-ts bolts spares spares !B )!P $)B )!P )!P )!P NB $)N EB $N EB QE EBB EBB QN NB $NB )BB $) $P5N $$) !BB !BBB $E)

holders spares co3ers panels accessories accessories

i)BP brac;ets spares P rows selected5

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 4-nction is e6ec-ted and 3eri4ied

FUNCTION
AIM: To write a P"8&?" bloc; -sin7 4-nction to 4ind the 7rade o4 the st-dent -sin7 c-rsors5 PROGRAM: &?"+ create or replace 4-nction 7rade,m$ n-mber:m) n-mber:mE n-mber1 ret-rn char is be7in i4 m$+NB and m)+NB and mE+NB then ret-rn MPA&&M2 else ret-rn MTAI"M2 end i42 end2

&?"+ 8 T-nction created5 &?"+ declare c-rsor c is select id:m$:m):mE 4rom st-dent2 a cSrowt/pe2 be7in open c2 loop 4etch c into a2 e6it when cSnot4o-nd2 -pdate st-dent set 7radeK7rade,a5m$:a5m):a5mE1 where idKa5id2 end loop2 commit2 close c2 end2

SAMPLE INPUT OUTPUT: &?"+8 P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom st-dent2 ID M$ M) ME T(TA" ' ADE ................................................................. csB$ !N RB NB $DN csB) RB QB PB ))B csBE PB NB !N $NN csB! QB DB QB ))B csBN NB !B !B $EB &?"+ select 9 4rom st-dent2 ID M$ M) ME T(TA" ' ADE ................................................................ csB$ !N RB NB $DN TAI" csB) RB QB PB ))B PA&& csBE PB NB !N NN TAI" csB! QB DB QB ))B PA&&

csBN

NB

!B

!B

$EB

TAI"

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 4-nction is e6ec-ted and 3eri4ied

PROCEDURE
A proced-re is a s-bpro7ram that per4orms a speci4ic action5 SYNTA>: Create or replace proced-re *proc_name+Iparameter listJis *local declaration+ Be7in ,e6ec-table statements1 Ie6ceptionJ ,e6ception handlers1 End2 NOTE: Uhile declarin7 3ariables in the declarati3e part o4 the proced-re bod/:we sho-ld not speci4/ the width o4 the datat/pe5 E75 Proced-re pro,name char,!B11 is Be7in ,set o4 statements12 End2 In the abo3e e6ample:char,!B1 sho-ld be replaced b/ char5 SYNTA> TO E>ECUTE: &<l+e6ec *proc_name+,parameters12

AIM: To write a P"8&?" bloc; to chec; whether the <-antit/ on hand is less than the reorder le3el then order more <-antit/ o4 the item and -pdate the table so that the chan7es are re4lected -sin7 proced-re,in mode15 PROGRAM: create or replace proced-re item4iles,orders in n-mber1 is <t/hand n-mber2 re_le3el n-mber2 ma6_le3el n-mber2 be7in select <t/_hand:rele3el:ma6le3el into <t/hand:re_le3el:ma6_le3el 4rom item4ile where itemcodeKorders2 i4 <t/hand*re_le3el then -pdate item4ile set <t/_handKre_le3elY<t/hand where itemcodeKorders2 else dbms_o-tp-t5p-t_line,Mitemle3el o;M12 end i42 e6ception when no_data_4o-nd then dbms_o-tp-t5p-t_line,Mno data ret-rnedM12 end 2 SAMPLE INPUT OUTPUT: &?"+ 8 Proced-re created5 &?"+ e6ec item4iles,)12 itemle3el o; P"8&?" proced-re s-ccess4-ll/ completed5

&?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .......... .......... .......... .......... .......... .......... $ eraser stationar/ $BB NB )BB E ) chain 4anc/ $NB RD )BB )N E tomato 3e7etable !PB N! $NQ N ! pen stationar/ EN NB DB P &?"+ e6ec item4iles,!12 P"8&?" proced-re s-ccess4-ll/ completed5 &?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .......... .......... .......... .......... .......... .......... $ eraser stationar/ $BB NB )BB E ) chain 4anc/ $NB RD )BB )N E tomato 3e7etable !PB N! $NQ N ! pen stationar/ DN NB DB P

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 proced-re is e6ec-ted and 3eri4ied5

PROCEDURE
AIM:

To write a P"8&?" bloc; to chec; whether the <-antit/ on hand is less than the reorder le3el then order more <-antit/ o4 the item and -pdate the table so that the chan7es are re4lected -sin7 proced-re,in L o-t mode15 PROGRAM: create or replace proced-re item4iles,orders n-mber:b o-t n-mber1 is <t/hand n-mber2 re_le3el n-mber2 ma6_le3el n-mber2 be7in select <t/_hand:rele3el:ma6le3el into <t/hand:re_le3el:ma6_le3el 4rom item4ile where itemcodeKorders2 i4 <t/hand*re_le3el then b:Kre_le3elY<t/hand 2 else dbms_o-tp-t5p-t_line,Mitemle3el o;M12 end i42 e6ception when no_data_4o-nd then dbms_o-tp-t5p-t_line,Mno data ret-rnedM12 end 2 &?"+8 Proced-re created5

&?"+ select 9 4rom item4ile2 ITEMC(DE ITEMC"(&E PDT_CT'% ?T%_#AND E"EVE" MAO"EVE" ITEM ATE .......... .......... .......... .......... .......... .......... ........... $ eraser stationar/ $BB NB )BB E ) chain 4anc/ !B RD )BB )N E tomato 3e7etable !PB N! $NQ N ! pen stationar/ DN NB DB P declare a n-mber:KLa2 b n-mber2

be7in item4iles,a:b12 dbms_o-tp-t5p-t_line,MThe 3al-e o4 b is :M\\to_char,b112 end2 &?"+8 Enter 3al-e 4or a: ) old ): a n-mber:KLa2 new ): a n-mber:K)2 The 3al-e o4 b is :$ED P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 proced-re is e6ec-ted and 3eri4ied5

PAC=AGES Pa%Ea5e S'e%&;&%at&on: S"nta#: Create pac;a7e *pac;a7e_name+ is *declaration+ Be7in ,e6ec-table statements1 End Ipac;a7e_nameJ Pa%Ea5e Bo " S"nta#: Create pac;a7e bod/ *pac;a7e_name+ is declaration+ Be7in ,e6ec-table statements1 End Ibod/_nameJ2

AIM: To write a P"8&?" pac;a7e that contains a proced-re and 4-nctions to chec; whether the 7i3en n-mber is a prime or not2 odd or e3en and positi3e or ne7ati3e5 PROGRAM: Pa%Ea5e S'e%&;&%at&on: create or replace pac;a7e pac;s is proced-re displa/2 4-nction prime,n n-mber1ret-rn 3archar2 4-nction odd,n n-mber1ret-rn 3archar2 4-nction positi3e,n n-mber1ret-rn 3archar2 end pac;s2 SAMPLE INPUT OUTPUT: &?"+8 Pac;a7e created5

Pa%Ea5e Bo " create or replace pac;a7e bod/ pac;s as proced-re displa/ is

a 3archar,$N12 m n-mber2 be7in m:KLm2 a:Kprime,m12 i4 aKMprimeM then dbms_o-tp-t5p-t_line,m \\ Mis a primeM12 else dbms_o-tp-t5p-t_line,m \\ Mis not primeM12 end i42 a:Kodd,m12 i4 aKModdM then dbms_o-tp-t5p-t_line,m \\ Mis oddM12 else dbms_o-tp-t5p-t_line,m \\ Mis e3enM12 end i42 a:Kpositi3e,m12 i4 aKMpositi3eM then dbms_o-tp-t5p-t_line,m \\ Mis a positi3e n-mberM12 else dbms_o-tp-t5p-t_line,m \\ Mis a ne7ati3e n-mberM12 end i42 end displa/2 4-nction prime,n n-mber1ret-rn 3archar is i n-mber2 4la7 n-mber2 be7in 4la7:KB2 4or i in )55n8) loop i4 mod,n:i1KB then 4la7:K$2 ret-rn MNot primeM2 end i42 end loop2 i4 4la7KB then ret-rn MprimeM2 end i42 end prime2 4-nction odd,n n-mber1ret-rn 3archar is be7in i4 mod,n:)1KB then ret-rn Me3enM2 else

ret-rn ModdM2 end i42 end odd2 4-nction positi3e,n n-mber1ret-rn 3archar is be7in i4 n+B then ret-rn Mpositi3eM2 else ret-rn Mne7ati3eM2 end i42 end positi3e2 end pac;s2 SAMPLE INPUT OUTPUT: &?"+ 8 Enter 3al-e 4or m: Q old P: m:KLm2 new P: m:KQ2 Pac;a7e bod/ created5 &?"+ e6ec pac;s5displa/2 Qis a prime Qis odd Qis a positi3e n-mber P"8&?" proced-re s-ccess4-ll/ completed5

RESULT: Th-s the P"8&?" bloc; pro7ram -sin7 pac;a7e is e6ec-ted and 3eri4ied5

También podría gustarte