Oracle Prgs PDF
Oracle Prgs PDF
NO:
01
EMPLOYEELOYEEDETAI
LS
DATE :
21-
06-
2018
AI
M:
Tocr
eat
eanEMPLOYEEt
abl
ewi
thnecessar
yfi
eldsandper
for
m anyoneLogi
cal
,
Compar
ison,
Group,
Sor
tandSetoper
ati
on.
ALGORI
THM:
St
ep1:St
artt
hepr
ocess.
St
ep2:Cr
eat
eat
abl
eEMPLOYEEwi
tht
hef
oll
owi
ngf
iel
dsEmpno,
namebyusi
ngcr
eat
e
commandandSetEmpnoasPRI
MARYKEY.
St
ep3:Descr
ibet
het
abl
e.
St
ep4:I
nser
tnumberofr
owsi
nEMPLOYEEt
abl
e.
St
ep5:Execut
eanyoneLogi
cal
,Compar
ison,
Group,
Sor
tandSetst
atement
s.
St
ep6:St
opt
hepr
ocess.
CODI
NG:
SQL>CREATETABLEEMPLOYEE(
Empnonumber
(10)
,const
rai
ntEmpno_
pkpr
imar
y
key
(Empno)
,namev
archar
(20)
,desi
gnat
ionv
archar
2(20)
,genderv
archar
2(4)
,age
number
(3)
,sal
arynumber
(5)
);
Tabl
ecr
eat
ed.
SQL>I
NSERTI
NTOEMPLOYEEVALUES(
&empno,
'&name'
,'
&desi
gnat
ion'
,'
&gender
',
&age,
&sal
ary
);
Ent
erv
aluef
orempno:
101
Ent
erv
aluef
orname:
Nav
een
Ent
erv
aluef
ordesi
gnat
ion:
Manager
Ent
erv
aluef
orgender
:mal
e
Ent
erv
aluef
orage:
21
Ent
erv
aluef
orsal
ary
:50000
ol
d 1:
INSERTI
NTOEMPLOYEEVALUES(
&empno,
'
&name'
,
'&desi
gnat
ion'
,
'&gender
',
&age,
&sal
ary
)
new 1:
INSERTI
NTOEMPLOYEEVALUES(
101,
'
Nav
een'
,
'Manager
',
'
mal
e'
,21,
50000)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOEMPLOYEEVALUES(
&empno,
'&name'
,'
&desi
gnat
ion'
,'
&gender
',
&age,
&sal
ary
);
Ent
erv
aluef
orempno:
102
Ent
erv
aluef
orname:
Nar
ayanan
Ent
erv
aluef
ordesi
gnat
ion:
gener
al_
manager
Ent
erv
aluef
orGENDER:
mal
e
Ent
erv
aluef
orage:
22
Ent
erv
aluef
orsal
ary
:45000
ol
d 1:
INSERTI
NTOEMPLOYEE
VALUES(
&empno,
'
&name'
,
'&desi
gnat
ion'
,
'&gender
',
&age,
&sal
ary
)
new 1:
INSERTI
NTOEMPLOYEEVALUES(
102,
'Nar
ayanan'
,'
gener
al_
manager
',
'mal
e'
,22,
45000)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOEMPLOYEEVALUES(
&empno,
'
&name'
,
'&desi
gnat
ion'
,
'&gender
',
&age,
&sal
ary
);
Ent
erv
aluef
orEmpno:
103
Ent
erv
aluef
orname:
Prasant
h
Ent
erv
aluef
ordesi
gnat
ion:
appr
ent
ice
Ent
erv
aluef
orGENDER:
mal
e
Ent
erv
aluef
orage:
20
Ent
erv
aluef
orsal
ary
:1000
ol
d 1:
INSERTI
NTOEMPLOYEEVALUES(
&empno,
'
&name'
,
'&desi
gnat
ion'
,
'&gender
',
&age,
&sal
ary
)
new1:
INSERTI
NTOEMPLOYEEVALUES(
103,
'Pr
asant
h',
'
appr
ent
ice'
,
'mal
e'
,20,
10)
1r
owcr
eat
ed.
SQL>SELECT*f
rom EMPLOYEEwher
esal
ary
>1000;
EMPNO NAME DESI
GNATI
ON GENDER AGE SALARY
-
--
--
--
--
- -
--
--
--
-- -
--
--
--
--
--
--
--
--
--
- -
--
--
--
--
-- -
--
--
--
---
--
--
--
--
--
--
101 Nav
een Manager mal
e 21 50000
102 Nar
ayanan gener
al_
manager mal
e 22 45000
SQL>SELECT*f
rom EMPLOYEEor
derbyagedesc;
-
--
--
--
--
---
--
--
--
-- -
--
--
--
--
--
--
--
--
--
-- -
--
--
--
--
-- -
--
--
--
---
--
--
--
--
--
102 Nar
ayanangener
al_
manager mal
e 22 45000
101 Nav
een Manager mal
e 21 50000
103 Pr
asant
h appr
ent
ice mal
e 20 1000
SQL>SELECT*f
rom EMPLOYEEwher
egender
=’mal
e’uni
onSELECT*f
rom EMPLOYEEwher
e
age>20;
-
--
--
--
--
---
--
--
--
--
- -
--
--
--
--
--
--
--
--
--
-- -
--
--
--
--
--
- -
--
--
--
---
--
--
--
--
--
--
101Nav
een Manager mal
e 21 50000
102Nar
ayanangener
al_
manager mal
e 22 45000
SQL>SELECTname,
sum(
sal
ary
)fr
om EMPLOYEEgr
oupbyname;
NAME SUM(
SALARY)
-
--
--
--
-- -
--
--
--
--
--
--
--
--
--
-
Nar
ayanan 45000
Nav
een 50000
Pr
asant
h 1000
SQL>SELECT*f
rom EMPLOYEEwher
eage>20andgender
=’mal
e’
;
-
--
--
--
--
- -
--
--
--
-- -
--
--
--
--
--
--
--
--
--
- -
--
--
--
--
-- -
--
--
--
---
--
--
--
--
--
--
101 Nav
een Manager mal
e 21 50000
102 Nar
ayanan gener
al_
manager mal
e 22 45000
EX.
NO:
02
LI
BRARYMANAGEMENTSYSTEM
DATE :
29-
06-
2018
AI
M:
Tocr
eat
eLi
brar
yManagementSy
stem t
odemonst
rat
etheuseofPr
imar
yKeyand
For
eignKey,
Creat
eaRepor
tusi
ngSELECTv
erbwi
tht
hef
iel
dsAccno,
Tit
le,
Dat
eofI
ssuef
or
t
hegi
venDat
eofRet
urn.
ALGORI
THM:
St
ep1:
Star
tthepr
ocess.
St
ep2:
Creat
etwot
abl
esMASTER,
TRANSACTI
ONwi
thnecessar
yfi
elds
St
ep3:
SetPRI
MARYKEYaccnoanduser
idi
nMASTERandTRANSACTI
ONt
abl
esr
espect
ivel
y.
St
ep4:
Inser
trequi
redVALUESt
othet
abl
esMASTERandTRANSACTI
ON.
St
ep5:
Creat
etopt
it
leandbot
tom t
it
leofr
epor
tusi
ngTTI
TLEandBTI
TLEcommand.
St
ep6:
Gener
atear
epor
tonapar
ti
cul
ardat
eofr
etur
nusi
ngSELECTcommandwi
thwher
e
condi
ti
on.
St
ep7:
Stopt
hepr
ocess.
CODI
NG:
SQL>CREATETABLEMast
er(
accnonumber
(4)
,const
rai
ntaccno_
pkpr
imar
ykey
(accno)
,t
it
le
v
archar
2(50)
,aut
horv
archar
2(10)
,r
atenumber
(6,
2))
;
Tabl
ecr
eat
ed.
SQL>CREATETABLETr
ansact
ion(
user
idv
archar
2(3)
,const
rai
ntuser
id_
pkpr
imar
y
key
(user
id)
,accno,
const
rai
ntaccno_
fkf
orei
gnkey
(accno)r
efer
encesMast
er,
doi
v
archar
2(10)
,dorv
archar
2(10)
);
Tabl
ecr
eat
ed.
SQL>descMast
er;
Name Nul
l
? Ty
pe
-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-- -
--
--
--
--
--
-- -
--
--
--
--
--
--
--
--
-
TI
TLE VARCHAR2(
50)
AUTHOR VARCHAR2(
10)
RATE NUMBER(
6,2)
SQL>descTr
ansact
ion;
Name Nul
l
? Ty
pe
-
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
--
-- -
--
--
--
--
- -
--
--
--
--
--
--
--
-
USERI
D NOTNULL VARCHAR2(
3)
ACCNO NUMBER(
4)
DOI VARCHAR2(
10)
DOR VARCHAR2(
10)
SQL>I
NSERTI
NTOMast
erVALUES(
'&accno'
,
'&t
it
le'
,
'&aut
hor
',
&rat
e);
Ent
erv
aluef
oraccno:
1001
Ent
erv
aluef
ort
it
le:
RDBMS
Ent
erv
aluef
oraut
hor
:Moor
thy
Ent
erv
aluef
orr
ate:
100
ol
d 1:
INSERTI
NTOMast
erVALUES(
'&accno'
,
'&t
it
le'
,
'&aut
hor
',
&rat
e)
new1:
INSERTI
NTOMast
erVALUES(
'1001'
,
'RDBMS'
,
'Moor
thy
',
100)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOMast
erVALUES(
'&accno'
,
'&t
it
le'
,
'&aut
hor
',
&rat
e);
Ent
erv
aluef
oraccno:
1002
Ent
erv
aluef
ort
it
le:
VBVC++
Ent
erv
aluef
oraut
hor
:Ramesh
Ent
erv
aluef
orr
ate:
200
ol
d 1:
INSERTI
NTOMast
erVALUES(
'&accno'
,
'&t
it
le'
,
'&aut
hor
',
&rat
e)
new 1:
INSERTI
NTOMast
erVALUES(
'1002'
,
'VBVC++'
,
'Ramesh'
,
200)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
;
Ent
erv
aluef
oruser
id:
A11
Ent
erv
aluef
oraccno:
1001
Ent
erv
aluef
ordoi
:08/
09/
2018
Ent
erv
aluef
ordor
:15/
09/
2018
ol
d 1:
INSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
new 1:
INSERTI
NTOTr
ansact
ionVALUES(
'A11'
,
'1001'
,
'08/
09/
2018'
,
'15/
09/
2018'
)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
;
Ent
erv
aluef
oruser
id:
B11
Ent
erv
aluef
oraccno:
1002
Ent
erv
aluef
ordoi
:10/
09/
2018
Ent
erv
aluef
ordor
:18/
09/
2018
ol
d 1:
INSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
new 1:
INSERTI
NTOTr
ansact
ionVALUES(
'B11'
,
'1002'
,
'10/
09/
2018'
,
'18/
09/
2018'
)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
;
Ent
erv
aluef
oruser
id:
456
Ent
erv
aluef
oraccno:
1001
Ent
erv
aluef
ordoi
:08/
09/
2018
Ent
erv
aluef
ordor
:15/
09/
2018
ol
d 1:
INSERTI
NTOTr
ansact
ionVALUES(
'&user
id'
,
'&accno'
,
'&doi
'
,'
&dor
')
new 1:
INSERTI
NTOTr
ansact
ionVALUES(
'456'
,
'1001'
,
'08/
09/
2018'
,
'15/
09/
2018'
)
1r
owcr
eat
ed.
SQL>SELECTMast
er.
accno,
Mast
er.
ti
tl
e,
Transact
ion.
doi
,
Transact
ion.
dorf
rom Mast
eri
nnerj
oin
Tr
ansact
ionwher
edor
='15/
09/
2018'
;
*
***
*BOOKDETAI
LS*
***
*
ACCNO TI
TLE DOI DOR
-
--
--
--
--
--
---
--
--
--
--
--
--
--
--
--
--
--
-- -
--
--
--
--
--
--
--
- -
--
--
--
--
--
--
-
*
***
*ENDOFBOOKDETAI
LS*
***
**
EX.
NO:
03
I
NVENTORYSYSTEM
DATE :
09-
07-
2018
AI
M:
Towr
it
ePL/
SQLpr
ogr
am t
oupdat
erat
efi
l
edby20%mor
e.Al
tert
abl
ebyaddi
ngaf
iel
d
noofi
temsandupdat
eVALUESwi
thoutusi
ngPL/
SQL.
ALGORI
THM:
St
ep1:
Star
tthepr
ocess.
St
ep2:
Creat
eat
abl
eINVENTORYwi
thf
iel
dspr
ono,
pronameandr
ate.
St
ep3:
Inser
tappr
opr
iat
eVALUESt
othet
abl
e.
St
ep4:
Creat
eaPL/
SQLcodet
omodi
fyt
heVALUESoft
hecol
umnr
ateby20%.
St
ep5:
Byusi
ngAl
tercommandaddacol
umnnoof
it
emst
othet
abl
e.
St
ep6:
SetVALUESf
ort
henoof
it
emsf
iel
dusi
ngUPDATEcommand.
St
ep7:
Stopt
hepr
ocess.
CODI
NG:
SQL>CREATETABLEI
nvent
ory
(pr
ononumber
(5)
,pr
onamev
archar
2(20)
,r
atenumber
(6,
2))
;
Tabl
ecr
eat
ed.
SQL>I
NSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e);
Ent
erv
aluef
orpr
ono:
123
Ent
erv
aluef
orpr
oname:
Pendr
ive
Ent
erv
aluef
orr
ate:
500
ol
d 1:
INSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e)
new 1:
INSERTI
NTOI
nvent
oryVALUES(
123,
'
Pendr
ive'
,
500)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e);
Ent
erv
aluef
orpr
ono:
456
Ent
erv
aluef
orpr
oname:
CD
Ent
erv
aluef
orr
ate:
50
ol
d 1:
INSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e)
new 1:
INSERTI
NTOI
nvent
oryVALUES(
456,
'
CD'
,
50)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e);
Ent
erv
aluef
orpr
ono:
789
Ent
erv
aluef
orpr
oname:
SdCar
d
Ent
erv
aluef
orr
ate:
300
ol
d 1:
INSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e)
new 1:
INSERTI
NTOI
nvent
oryVALUES(
789,
'
SdCar
d',
300)
1r
owcr
eat
ed.
SQL>I
NSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e);
Ent
erv
aluef
orpr
ono:
653
Ent
erv
aluef
orpr
oname:
USB
Ent
erv
aluef
orr
ate:
500
ol
d 1:
INSERTI
NTOI
nvent
oryVALUES(
&pr
ono,
'
&pr
oname'
,
&rat
e)
new 1:
INSERTI
NTOI
nvent
oryVALUES(
653,
'
USB'
,
500)
1r
owcr
eat
ed.
SQL> decl
are
2begi
n
3updat
eInv
ent
orysetr
ate=r
ate+(
rat
e*20/
100)
;
4end;
5/
PL/
SQLpr
ocedur
esuccessf
ull
ycompl
eted.
SQL>ALTERTABLEI
nvent
oryADD(
noof
it
em number
(3)
);
Tabl
eal
ter
ed.
SQL>descI
nvent
ory
;
Name Nul
l
? Ty
pe
-
--
--
--
--
--
- -
--
--
--
- -
--
--
--
--
--
-
PRONO NUMBER(
5)
PRONAME VARCHAR2(
20)
RATE NUMBER(
6,2)
NOOFI
TEM NUMBER(
3)
SQL>SELECT*f
rom I
nvent
ory
;
-
--
--
--
--
--
---
--
--
--
--
--
--
--
--
--
- -
--
--
--
--
--
- -
--
--
--
--
--
--
--
-
123 Pendr
ive 600
456 CD 678
789 SdCar
d 360
SQL>UPDATEI
nvent
orySETnoof
it
em=20WHEREpr
ono=123;
1r
owupdat
ed.
SQL>UPDATEI
nvent
orySETnoof
it
em=10WHEREpr
ono=456;
1r
owupdat
ed.
SQL>UPDATEI
nvent
orySETnoof
it
em=30WHEREpr
ono=789;
1r
owupdat
ed.
SQL>UPDATEI
nvent
orySETnoof
it
em=40WHEREpr
ono=653;
1r
owupdat
ed.
SQL>SELECT*f
rom I
nvent
ory
;
-
--
--
--
--
---
--
--
--
--
--
--
--
--
---
--
--
--
--
- -
--
--
--
--
--
--
--
--
123 Pendr
ive 600 20
456 CD 678 10
789 SdCar
d 360 30
AI
M:
Towr
it
ePL/
SQLpr
ogr
am t
ospl
i
tSt
udentt
abl
eint
otwot
abl
esnamel
yPassandFai
l
basedont
heResul
tusi
ngCur
sor
.
ALGORI
THM:
St
ep1:
Star
tthepr
ocess.
St
ep2:
Creat
eat
abl
eSTUDENTwi
tht
hef
iel
dsr
no,
name,
m1,
m2,
totandr
es.
St
ep3:
Inser
ttheappr
opr
iat
eVALUESt
othet
abl
e.
St
ep4:
Creat
eanot
hert
abl
ePASSandFAI
Lwi
tht
hef
iel
dsofSTUDENTt
abl
e.
St
ep5:
Creat
eCURSORt
ocheckt
her
esul
tinSTUDENTt
abl
ewhet
heri
tisPassmov
ether
ecor
d
t
othePASSt
abl
eel
semov
eitt
otheFAI
Ltabl
e.
St
ep6:
Stopt
hepr
ocess.
CODI
NG:
SQL>SETser
ver
out
puton;
SQL>CREATETABLESt
udent
(rnonumber
(5)
,namev
archar
2(30)
,m1number
(3)
,m2
number
(3)
,t
otnumber
(3)
,r
esv
archar
2(4)
);
Tabl
ecr
eat
ed.
SQL>I
NSERTI
NTOSt
udentVALUES(
&rno,
'
&name'
,
&m1,
&m2,
&tot
,'
&res'
);
Ent
erv
aluef
orr
no:
1166
Ent
erv
aluef
orname:
PrakashP
Ent
erv
aluef
orm1:
50
Ent
erv
aluef
orm2:
60
Ent
erv
aluef
ort
ot:
110
Ent
erv
aluef
orr
es:
pass
ol
d 1:
INSERTI
NTOSt
udentVALUES(
&rno,
'
&name'
,
&m1,
&m2,
&tot
,'
&res'
)
new1:
INSERTI
NTOSt
udentVALUES(
1166,
'Pr
akashP'
,
50,
60,
110,
'
pass'
)
1r
owcr
eat
ed.
SQL>/
Ent
erv
aluef
orr
no:
1188
Ent
erv
aluef
orname:
Mar
i
Ent
erv
aluef
orm1:
30
Ent
erv
aluef
orm2:
30
Ent
erv
aluef
ort
ot:
60
Ent
erv
aluef
orr
es:
fai
l
ol
d 1:
INSERTI
NTOSt
udentVALUES(
&rno,
'
&name'
,
&m1,
&m2,
&tot
,'
&res'
)
new 1:
INSERTI
NTOSt
udentVALUES(
1188,
'Mar
i',
30,
30,
60,
'
fai
l
')
1r
owcr
eat
ed.
SQL>CREATETABLEPass(
rnonumber
(5)
,namev
archar
2(30)
,t
otnumber
(3)
,r
esv
archar
2(4)
);
Tabl
ecr
eat
ed.
SQL>CREATETABLEFai
l
(rnonumber
(5)
,namev
archar
2(30)
,t
otnumber
(3)
,r
esv
archar
2(4)
);
Tabl
ecr
eat
ed.
SQL> decl
are
2cur
sorpi
sSELECT*f
rom st
udent
;
3stSt
udent
%rowt
ype;
4begi
n
5DELETEf
rom Pass;
6DELETEf
rom Fai
l
;
7openp;
8l
oop
9f
etchpi
ntost
;
10ex
itwhenp%not
found;
11i
f(
st.
res='
Pass'
)then
12I
NSERTI
NTOPassVALUES(
st.
rno,
st.
name,
st.
tot
,st
.r
es)
;
13el
se
14I
NSERTI
NTOFai
lVALUES(
st.
rno,
st.
name,
st.
tot
,st
.r
es)
;
15endi
f;
16endl
oop;
17dbms_
out
put
.put
_li
ne(
'Tabl
eSuccessf
ull
ySpl
i
ted'
);
18cl
osep;
19end;
20/
Tabl
eSuccessf
ull
ySpl
i
ted
PL/
SQLpr
ocedur
esuccessf
ull
ycompl
eted.
SQL>SELECT*f
rom Pass;
-
--
--
--
--
---
--
--
--
--
--
--
---
--
--
--
-- -
--
--
--
--
-
1166 Pr
akashP 110 pass
SQL>SELECT*f
rom Fai
l
;
-
--
--
--
---
--
--
--
--
--
--
- -
--
--
-- -
--
--
--
--
--
1188 Mar
i 60 f
ail
EX.
NO:
05
BEFOREDATABASETRI
GGER
DATE :
10-
08-
2018
AI
M:
Tocr
eat
eaDat
abaseTr
iggert
ocheckt
hedat
aval
i
dit
yonI
nvent
orymanagement
sy
stem.
ALGORI
THM:
St
ep1:
Star
tthepr
ocess.
St
ep2:
CREATETABLEPMASTERwi
tht
henecessar
yfi
eldsandsetpnoasPRI
MARYKEY.
St
ep3:
Creat
eat
abl
ePTRANSwi
tht
henecessar
yfi
eldsandsett
noasPRI
MARYKEYandpno
asFOREI
GNKEY.
St
ep4:
Creat
eaTRI
GGERpm f
orPMASTERt
abl
etocheckNULLVALUESoft
heCol
umnName
bef
oreI
nser
ti
ngorUpdat
ing.
St
ep5:
Creat
eaTRI
GGERptf
orPTRANSt
abl
etocheckt
hecapaci
tynotl
esst
hanorequal
to
zer
oBef
oreI
nser
ti
ngorUpdat
ing.
St
ep6:
Stopt
hepr
ocess.
CODI
NG:
SQL>CREATETABLEPMast
er(
pnonumber
(3)
,const
rai
ntpno_
pkpr
imar
ykey
(pno)
,name
v
archar
2(15)
,r
atenumber
(5,
2))
;
Tabl
ecr
eat
ed.
SQL>CREATETABLEPTr
ans(
tnonumber
(6)
,const
rai
ntt
no_
pkpr
imar
ykey
(tno)
,pno,
const
rai
nt
pno_
fkf
orei
gnkey
(pno)r
efer
encesPMast
er,
pav
ail
number
(3)
,qt
ynumber
(3)
);
Tabl
ecr
eat
ed.
SQL> Cr
eat
eorRepl
aceTr
iggerpm bef
oreI
nser
torUpdat
eonPMast
erf
oreachr
ow
2decl
are
3cur
sorcm i
sSELECTnamef
rom PMast
er;
4begi
n
5i
f:
new.
namei
snul
lthen
6r
aise_
appl
i
cat
ion_
err
or(
-20000,
'
NamecannotbeNULL'
);
7endi
f;
8end;
9/
Tr
iggercr
eat
ed.
SQL> cr
eat
eorr
epl
acet
ri
ggerptbef
orei
nser
torupdat
eonPTr
ansf
oreachr
ow
2decl
are
3cur
sorcti
sSELECTpav
ail
from PTr
ans;
4begi
n
5i
f:
new.
pav
ail
<=0t
hen
6r
aise_
appl
i
cat
ion_
err
or(
-20001,
'
Productshoul
dav
ail
abl
e'
);
7endi
f;
8end;
9/
Tr
iggercr
eat
ed.
SQL>I
NSERTI
NTOPMast
erVALUES(
&pno,
'
&name'
,
&rat
e);
Ent
erv
aluef
orpno:
1
Ent
erv
aluef
orname:
Ent
erv
aluef
orr
ate:
200
ol
d 1:
INSERTI
NTOPMast
erVALUES(
&pno,
'
&name'
,
&rat
e)
new 1:
INSERTI
NTOPMast
erVALUES(
1,'
'
,200)
I
NSERTI
NTOPMast
erVALUES(
1,'
'
,200)
ERRORatl
i
ne1:
ORA-
20000:
NamecannotbeNULL
ORA-
06512:
at"
SYSTEM.
PM"
,li
ne5
ORA-
04088:
err
ordur
ingexecut
ionoft
ri
gger'
SYSTEM.
PM'
SQL>I
NSERTI
NTOPTr
ansVALUES(
&tno,
&pno,
&pav
ail
,
&qt
y);
Ent
erv
aluef
ort
no:
111
Ent
erv
aluef
orpno:
1
Ent
erv
aluef
orpav
ail
:0
Ent
erv
aluef
orqt
y:10
ol
d 1:
INSERTI
NTOPTr
ansVALUES(
&tno,
&pno,
&pav
ail
,
&qt
y)
new 1:
INSERTI
NTOPTr
ansVALUES(
111,
1,
0,
10)
I
NSERTI
NTOPTr
ansVALUES(
111,
1,
0,
10)
ERRORatl
i
ne1:
ORA-
20001:
Productshoul
dbeav
ail
abl
e
ORA-
06512:
at"
SYSTEM.
PT"
,li
ne5
ORA-
04088:
err
ordur
ingexecut
ionoft
ri
gger'
SYSTEM.
PT'
EX.
NO:
06
EXCEPTI
ONHANDLI
NG
DATE :
07-
09-
2018
AI
M:
Towr
it
eaPL/
SQLpr
ogr
am t
oRai
set
heExcept
ionsi
nBandAccountManagement
Sy
stem.
ALGORI
THM:
St
ep1:
Star
tthepr
ocess.
St
ep2:
CREATETABLESAVI
NGSwi
tht
hef
iel
dsaccno,
name,
transandamount
.
St
ep3:
Inser
ttheVALUESt
othet
abl
e.
St
ep4:
Creat
eEXCEPTI
ONl
i
kenoamtandi
nval
i
damt
.
St
ep5:
Checkt
heamtVALUESi
fiti
sNULLt
henRai
senoamtEXCEPTI
ON.
St
ep6:
Checkt
heamtVALUESi
fiti
sNegat
iveorZer
othenRai
sei
nval
i
damtEXCEPTI
ON.
St
op7:
Stopt
hepr
ocess.
CODI
NG:
SQL>SETser
ver
out
puton;
SQL>CREATETABLESav
ings(
accnonumber
(10)
,namev
archar
2(20)
,t
ransv
archar
2(10)
,amount
number
(10)
);
Tabl
ecr
eat
ed.
SQL>I
NSERTI
NTOSav
ingsVALUES(
&accno,
'
&name'
,
'&t
rans'
,
&amount
);
Ent
erv
aluef
oraccno:
100
Ent
erv
aluef
orname:
Raj
esh
Ent
erv
aluef
ort
rans:
deposi
t
Ent
erv
aluef
oramount
:10000
ol
d 1:
INSERTI
NTOSav
ingsVALUES(
&accno,
'
&name'
,
'&t
rans'
,
&amount
)
new 1:
INSERTI
NTOSav
ingsVALUES(
100,
'Raj
esh'
,
'deposi
t'
,
10000)
1r
owcr
eat
ed.
SQL>/
Ent
erv
aluef
oraccno:
101
Ent
erv
aluef
orname:
Uthr
a
Ent
erv
aluef
ort
rans:
wit
hdr
aw
Ent
erv
aluef
oramount
:-2000
ol
d 1:
INSERTI
NTOSav
ingsVALUES(
&accno,
'
&name'
,
'&t
rans'
,
&amount
)
new 1:
INSERTI
NTOSav
ingsVALUES(
101,
'Ut
hra'
,
'wi
thdr
aw'
,
-2000)
1r
owcr
eat
ed.
SQL> decl
are
2i
nval
i
damtexcept
ion;
3noamtexcept
ion;
4amtSav
ings.
amount
%ty
pe;
5begi
n
6SELECTamounti
ntoamtf
rom Sav
ingswher
eaccno=&accno;
7i
famt
<=0t
hen
8r
aisei
nval
i
damt
;
9el
sifamti
sNULLt
hen
10r
aisenoamt
;
11dbms_
out
put
.put
_li
ne(
to_
char
(amt
));
12endi
f;
13ex
cept
ion
14wheni
nval
i
damtt
hen
15dbms_
out
put
.put
_li
ne(
'Amounti
sZer
oorNegat
ive'
);
16whennoamtt
hen
17dbms_
out
put
.put
_li
ne(
'NoAmountVal
ue'
);
18whenot
her
sthen
19dbms_
out
put
.put
_li
ne(
'NoSuchAccno'
);
20end;
21/
Ent
erv
aluef
oraccno:
101
ol
d 6:
SELECTamounti
ntoamtf
rom Sav
ingswher
eaccno=&accno;
new 6:
SELECTamounti
ntoamtf
rom Sav
ingswher
eaccno=101
Amounti
sZer
oorNegat
ive
PL/
SQLpr
ocedur
esuccessf
ull
ycompl
eted.
SQL>/
Ent
erv
aluef
oraccno:
105
ol
d 9:
wher
eaccno=&accno;
new 9:
wher
eaccno=105;
NoSuchAccno
PL/
SQLpr
ocedur
esuccessf
ull
ycompl
eted.
*
**ALLTHEBEST*
**