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

Assignment 34

The document contains a series of SQL commands for creating and manipulating database tables related to buses, routes, subjects, teachers, and areas. It includes functions for querying and inserting data, as well as updating records based on specific criteria. The document also features various SELECT statements to retrieve information from the created tables.

Uploaded by

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

Assignment 34

The document contains a series of SQL commands for creating and manipulating database tables related to buses, routes, subjects, teachers, and areas. It includes functions for querying and inserting data, as well as updating records based on specific criteria. The document also features various SELECT statements to retrieve information from the created tables.

Uploaded by

hellosachin5
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

As

signment3
Seta
s
hine=
#sel
ect*f
rombus
;
bus
no|c
apac
ity|dept
nm
-
--
--
--
+--
--
--
--
--
+--
--
--
--
--
-
1
110| 5
0|ex
pres
s
5
758| 89|s
uper
fas
t
(
2rows
)
s
hine=
#sel
ect*f
romr
out
e;
r
out
eno|s
our
ce|des
tinat
ion|no_
of_
staat
ion
-
--
--
--
--
+--
--
--
--
-+-
--
--
--
--
--
--
+--
--
--
--
--
--
--
--
1
02|c
hennai|kol
kat
a | 8
1
01|nas
hik|mumbai | 4
(
2rows
)
s
hine=
#c r
eatetabl
eb_
r(bus
noi
ntr
efer
enc
esbus
(bus
no)
,rout
enoi
ntr
efer
enc
es
r
oute(
routeno)
);
CREATETABLE
s
hine=
#ins
erti
ntob_
rval
ues
(11
10,
102)
,(5
758,
101
);
I
NSERT02
s
hine=
#sel
ect*f
romb_
r;
bus
no|r
out
eno
-
--
--
--
+--
--
--
--
-
1
110| 1
02
5
758| 1
01
(
2rows
)

#ques
tion1
s
hine=#creat
eorreplac
ef unct
ioncur
dtls
(int
)returnsvoi
das'decl
arerrec
ord;
cur
c
ursorforsel
ect*fr
omr oute,
bus,
b_rwherebus.
busno=$1andbus.
busno=
b_r
.bus
no
andr oute.
rout
eno=b_r.
rout
eno;beginopencur;
loopf
etchcurint
or;
exi
twhennot
found;rais
enotice'
'
%%%%' ',
r.
routeno,r
.sour
ce,
r.
dest
inat
ion,
r.
no_of
_st
aat
ion;
end
loop;closecur;
end;'l
anguage'plpgsql
';
CREATEFUNCTI
ON
s
hine=
#sel
ectc
urdt
ls(
111
0);
NOTI
CE:1
02c
hennaikol
kat
a8
c
urdt
ls
-
--
--
--
--

(
1row)

#ques
tion2
shine=#c reateorreplacef
unc ti
onbdt l
s(text
,t
ext)returnsv oidas' declar
errecor
d;
curc ursorforselect*fr
ombus ,route,
b_rwhereroute.source= $1and
route.destinati
on=$2andbus.busno=b_r.
busnoandr oute.r
out eno=b_ r.
rout
eno;
begi
n
openc ur;
loopf et
chcurint
or ;exitwhennotfound;raisenot ice''
%%
%''
,r.
bus no,r.
capaci
ty,
r.
deptnm;endl oop;
closecur;end;'l
ang uag e'plpgsql
'
;
CREATEFUNCTI
ON
s
hine=
#sel
ectbdt
ls(
'ch
ennai
'
,'
kol
kat
a')
;
NOTI
CE:1
1105
0ex
pres
s
bdt
ls
-
--
--
--

(
1row)

Setb

s
hine=
#cr
eat
etabl
etec
hr(
tnoi
ntpr
imar
ykey
,tnamev
arc
har
(20)
,ag
eint
,yr
_ex
pint
);
CREATETABLE
s
hine=
#cr
eat
etabl
esubj
ct(
snoi
ntpr
imar
ykey
,namev
arc
har
(15
));
CREATETABLE
s
hine=
#c reatet
abl
et_
sub(
tnoi
ntr
efer
enc
est
ech
r(t
no)
,snoi
ntr
efer
enc
es
s
ubjct
(sno));
CREATETABLE
s
hine=
#inserti
ntotec
hr
v
alues(
1,'
mr.
karan'
,
45,
10)
,(2,
'
mrs
.sh
arma'
,
35,
7),
(3,
'
mr.
pat
el'
,
28,
2);
I
NSERT03
s
hine=
#ins
erti
ntos
ubj
ctv
alues
(11
,'
mat
hs'
),
(12,
'
sci
enc
e')
,(1
3,'
eng
lis
h')
;
I
NSERT03
s
hine=
#ins
erti
ntot
_subv
alues
(1,
11)
,(2,
12)
,(3,
13)
;
I
NSERT03
s
hine=
#sel
ect*f
romt
ech
r;
t
no|t
name |ag
e|y
r_ex
p
-
--
--
+--
--
--
--
--
--
+--
--
-+-
--
--
--
-
1|mr
.kar
an |45| 1
0
2|mr
s.s
har
ma|35| 7
3|mr
.pat
el|28| 2
(
3rows
)
s
hine=
#sel
ect*f
roms
ubj
ct;
s
no|name
-
--
--
+--
--
--
--
-
1
1|mat
hs
1
2|s
cienc
e
1
3|eng
lis
h
(
3rows
)

s
hine=
#sel
ect*f
romt
_sub;
t
no|s
no
-
--
--
+--
--
-
1|1
1
2|1
2
3|1
3
(
3rows
)

#ques
tion1
shi
ne= #c r
eat eorr eplacefunctiontdtl
(text)returnsv
oidas' dec
l arerrecord;
cur
cursorfors electtechr.t
namef romt echr,
subjct,
t_s
ubwh eresubjct.name=$1and
techr.
tno=t_sub.tnoands ubjct
.sno=t_s
ub.sno;beginopenc ur;
loopf et
chcurint
or;
exitwhennotf ound;raisenotice''
%'
',
r.
tname; endloop;closecur;end;
'
languag e'
plpg sql'
;
CREATEFUNCTI
ON
s
hine=
#sel
ectt
dtl
('
sci
enc
e')
;
NOTI
CE:mr
s.s
har
ma
t
dtl
-
--
--
-

(
1row)

Setc
shi
ne=#creat
etabl
eper
son(
pnoi
ntpr
imar
ykey
,namev
arc
har
(20)
,br
thdt
date,
inc
omemoney);
CREATETABLE
s
hine=#creat
etabl
ear
ea(
aidi
ntpr
imar
ykey
,anamev
arc
har
(20)
,ar
type
v
archar(
5));
CREATETABLE
s
hine=
#al
tert
abl
eper
sonaddai
dintr
efer
enc
esar
ea(
aid)
;
ALTERTABLE
s
hine=
#sel
ect*f
romper
son;
pno|name|br
thdt|i
ncome|ai
d
-
--
--
+--
--
--
+--
--
--
--
+--
--
--
--
+--
--
-
(
0rows
)
s
hine=
#inser
tint
oar ea
v
alues(
111
,'
dig
hi'
,
'ur
ban')
,(1
12,
'
alandi
'
,'
urban'
),
(11
3,'
vadg
aon'
,
'r
ural
')
;
I
NSERT03
s
hine=#inser
tintopers
onv alues(1
,'
karan'
,
'2000-
1 2-
1
6',
40000),
(2,
'
ria'
,
'199
0-1
1-23'
,80000),
(3,
'
sart
h ak'
,'
1998-
07-
19'
,
90000)
;
I
NSERT03
s
hine=
#updat
eper
sons
etai
d=1
11wh
erepno=
1;
UPDATE1
s
hine=
#updat
eper
sons
etai
d=1
12wh
erepno=
2;
UPDATE1
s
hine=
#updat
eper
sons
etai
d=1
13wh
erepno=
3;
UPDATE1
s
hine=
#sel
ect*f
romar
ea;
ai
d|aname|ar
type
-
--
--
+--
--
--
--
-+-
--
--
--
-
1
11|di
ghi|ur
ban
1
12|al
andi|ur
ban
1
13|v
adg
aon|r
ural
(
3rows
)

s
hine=
#sel
ect*f
romper
son;
pno|name |br
thdt|i
ncome |ai
d
-
--
--
+--
--
--
--
-+-
--
--
--
--
--
-+-
--
--
--
--
--
--
+--
--
-
1|kar
an |2000-
12-
16|?40,
000.
00|1
11
2|r
ia |1
990-
11-
23|?80,
000.
00|1
12
3|s
art
hak|1
998-
07-
19|?90,
000.
00|1
13
(
3rows
)
#ques
tion1
s
hine=#creat
eorr eplac
efunct
ionpdt
ls(i
nt)ret
urnsv
oidas'declarerrecor
d;cur
c
ursorforsel
ec tnamefrompersonwh
ereex t
ract(
monthf
rombr thdt)
=$1;
begi
nopen
c
ur;l
oopfetchcurintor;
exitwh
ennotfound;r
aisenot
ice'
'
%''
,
r.name;endloop;c
los
e
c
ur;end;'
language'
plpgs
ql'
;
CREATEFUNCTI
ON
s
hine=
#sel
ectpdt
ls(
11)
;
NOTI
CE:r
ia
pdt
ls
-
--
--
--

(
1row)

#ques
tion2
shi
ne= #createorreplacefunct
ionpname( text)r
eturnsvoidas'dec
lar
err ecor
d;c
ur
cur
sorf orselectnamef romperson,areawh er
earea.art
ype=$1and
person.ai
d=area.ai
d;begi
nopenc ur;
loopfetchcurint
or ;
ex i
twhennotfound;
rai
se
not
ice''
%''
,r
.name;endloop;cl
osec ur
; end;
'l
anguage'plpgsql
';
CREATEFUNCTI
ON
s
hine=
#sel
ectpname(
'ur
ban'
);
NOTI
CE:kar
an
NOTI
CE:r
ia
pname
-
--
--
--

(
1row)

#ques
tion3
shi
ne=#createorreplacefunct
ionprnm()r etur
nsvoidas'dec
larerrecord;cur
cur
sorforselec
tnamef r
omper sonwherei nc
omebet weenmoney(50000)and
money(1
00000);
beg i
nopenc ur
;l
oopf et
chc urint
or;exitwhennotfound;
rais
e
not
ice'
'
%''
,r
.name;endloop;
clos
ec ur;
end;'
language'
plpgsql
'
;
CREATEFUNCTI
ON
s
hine=
#sel
ectpr
nm(
);
NOTI
CE:r
ia
NOTI
CE:s
art
hak
pr
nm
-
--
--
-

(
1row)

You might also like