0% found this document useful (0 votes)
3 views11 pages

Oracle Code

The document outlines SQL commands for granting execute privileges on various object types, including Vehicle, Fuel, Driver, Accident, Staff, Schedule, Maintenance, Trip, and Insurance, to a specified user. It also includes the creation of these object types along with their associated methods for displaying details. Additionally, there are examples of anonymous blocks for testing the functionality of each object type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views11 pages

Oracle Code

The document outlines SQL commands for granting execute privileges on various object types, including Vehicle, Fuel, Driver, Accident, Staff, Schedule, Maintenance, Trip, and Insurance, to a specified user. It also includes the creation of these object types along with their associated methods for displaying details. Additionally, there are examples of anonymous blocks for testing the functionality of each object type.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Gr

antEXECUTEPr
ivi
l
egesf
orObj
ectTy
pes

GRANTEXECUTEONVehi
cleTOuser
name;

GRANTEXECUTEONFuel
TOuser
name;

GRANTEXECUTEONDr
iverTOuser
name;

GRANTEXECUTEONAcci
dentTOuser
name;

GRANTEXECUTEONSt
affTOuser
name;

GRANTEXECUTEONSchedul
eTOuser
name;

GRANTEXECUTEONMai
ntenanceTOuser
name;

GRANTEXECUTEONTr
ipTOuser
name;

GRANTEXECUTEONI
nsur
anceTOuser
name;

Gr
antEXECUTEPr
ivi
l
egesonDBMS_
OUTPUT

GRANTEXECUTEONSYS.
DBMS_
OUTPUTTOuser
name;

Gr
antSy
stem Pr
ivi
l
egesf
orObj
ectCr
eat
ion

GRANTCREATETYPETOuser
name;

Gr
antSELECT,
INSERT,
UPDATE,
DELETEPr
ivi
l
egesonUnder
lyi
ngTabl
es(
ifappl
i
cabl
e)

GRANTSELECT,
INSERT,
UPDATE,
DELETEONt
abl
e_nameTOuser
name;

Cr
eat
eandUseObj
ectTy
pes

1.Vehi
cleTy
pe
CREATEORREPLACETYPEVehi
cleASOBJECT(

v
ehi
cle_
idI
NT,

v
ehi
cle_
numberVARCHAR2(
10)
,

seat
ing_
capaci
tyI
NT,

MEMBERFUNCTI
ONdi
spl
ay_
det
ail
sRETURNVARCHAR2
)
;

CREATEORREPLACETYPEBODYVehi
cleAS

MEMBERFUNCTI
ONdi
spl
ay_
det
ail
sRETURNVARCHAR2I
S

BEGI
N

RETURN' Vehicl
eID: '
||vehi
cle_
id|
|'
,Vehi
cleNumber
:'|
|vehi
cle_
number|
|'
,Seat
ing
Capaci
ty:
'||
seating_capacit
y;

ENDdi
spl
ay_
det
ail
s;

END;

2.Fuel
Type
CREATEORREPLACETYPEFuel
ASOBJECT(

f
uel
_i
dINT,

v
ehi
cle_
idI
NT,

d_
fuel
i
ngDATE,

amount
_of
_fuel
DECI
MAL(
5,2)
,

MEMBERFUNCTI
ONf
uel
_i
nfoRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYFuel
AS

MEMBERFUNCTI
ONf
uel
_i
nfoRETURNVARCHAR2I
S

BEGI
N

RETURN'Fuel
ID:
'||
fuel
_i
d||
',Vehi
cleI
D:'
||v
ehi
cle_
id|
|'
,AmountofFuel
:'|
|
amount
_of_
fuel
;

ENDf
uel
_i
nfo;
END;

3.Dr
iverTy
pe
CREATEORREPLACETYPEDr
iverASOBJECT(

dr
iver
_idI
NT,

f
_nameVARCHAR2(
50)
,

l
_nameVARCHAR2(
50)
,

dr
iver
_p_
numberI
NT,

l
i
cense_
numberVARCHAR2(
20)
,

MEMBERFUNCTI
ONdi
spl
ay_
dri
verRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYDr
iverAS

MEMBERFUNCTI
ONdi
spl
ay_
dri
verRETURNVARCHAR2I
S

BEGI
N

RETURN'Dri
verI
D:'
||dr
iver
_id|
|'
,Name:
'||
f_name|
|''
||l
_name|
|'
,Li
cense:
'||
l
i
cense_number
;

ENDdi
spl
ay_
dri
ver
;

END;

4.Acci
dentTy
pe
CREATEORREPLACETYPEAcci
dentASOBJECT(

acci
dent
_idI
NT,

v
ehi
cle_
idI
NT,
dat
e_and_
timeDATE,

l
ocat
ionVARCHAR2(
50)
,

MEMBERFUNCTI
ONacci
dent
_det
ail
sRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYAcci
dentAS

MEMBERFUNCTI
ONacci
dent
_det
ail
sRETURNVARCHAR2I
S

BEGI
N

RETURN'
Acci
dentI
D:'
||acci
dent
_id|
|'
,Vehi
cleI
D:'
||v
ehi
cle_
id|
|'
,Locat
ion:
'||
locat
ion;

ENDacci
dent
_det
ail
s;

END;

5.St
affTy
pe
CREATEORREPLACETYPESt
affASOBJECT(

st
aff
_idI
NT,

f
ir
st_
nameVARCHAR2(
50)
,

l
ast
_nameVARCHAR2(
50)
,

depar
tmentVARCHAR2(
50)
,

MEMBERFUNCTI
ONdi
spl
ay_
staf
fRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYSt
affAS

MEMBERFUNCTI
ONdi
spl
ay_
staf
fRETURNVARCHAR2I
S

BEGI
N

RETURN'
Staf
fID:
'||
staf
f_i
d||
',Name:
'||
fir
st_
name|
|''
||l
ast
_name|
|'
,Depar
tment
:'|
|
depar
tment
;

ENDdi
spl
ay_
staf
f;

END;

6.Schedul
eTy
pe
CREATEORREPLACETYPESchedul
eASOBJECT(

schedul
e_i
dINT,

depar
tur
e_t
imeDATE,

ar
ri
val
_ti
meDATE,

f
requency
_of
_ser
viceVARCHAR2(
30)
,

v
ehi
cle_
idI
NT,

MEMBERFUNCTI
ONschedul
e_det
ail
sRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYSchedul
eAS

MEMBERFUNCTI
ONschedul
e_det
ail
sRETURNVARCHAR2I
S

BEGI
N

RETURN'ScheduleID:'
||schedul
e_i
d||'
,Depar
tur
e:'
||depar
tur
e_t
ime|
|'
,Ar
ri
val
:'|
|
ar
ri
val
_ti
me||
',Frequency:
'||fr
equency_
of_
servi
ce;

ENDschedul
e_det
ail
s;

END;

7.Mai
ntenanceTy
pe
CREATEORREPLACETYPEMai
ntenanceASOBJECT(

mai
ntenance_
idI
NT,
v
ehi
cle_
idI
NT,

dat
e_of
_ser
viceDATE,

t
ype_
of_
ser
viceVARCHAR2(
30)
,

MEMBERFUNCTI
ONmai
ntenance_
inf
oRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYMai
ntenanceAS

MEMBERFUNCTI
ONmai
ntenance_
inf
oRETURNVARCHAR2I
S

BEGI
N

RETURN' Mai
ntenanceI
D:'
||mai
ntenance_
id|
|'
,Vehi
cleI
D:'
||v
ehi
cle_
id|
|'
,Ty
pe:
'||
t
ype_of
_ser
vice;

ENDmai
ntenance_
inf
o;

END;

8.Tr
ipTy
pe
CREATEORREPLACETYPETr
ipASOBJECT(

t
ri
p_i
dINT,

dat
e_and_
timeDATE,

st
art
ing_
poi
ntVARCHAR2(
50)
,

endi
ng_
poi
ntVARCHAR2(
50)
,

v
ehi
cle_
idI
NT,

MEMBERFUNCTI
ONt
ri
p_i
nfoRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYTr
ipAS
MEMBERFUNCTI
ONt
ri
p_i
nfoRETURNVARCHAR2I
S

BEGI
N

RETURN'Tri
pID:
'||
tri
p_i
d||
',St
art
:'|
|st
art
ing_
poi
nt|
|'
,End:
'||
endi
ng_
poi
nt|
|'
,Dat
e:'
||
dat
e_and_
time;

ENDt
ri
p_i
nfo;

END;

9.I
nsur
anceTy
pe
CREATEORREPLACETYPEI
nsur
anceASOBJECT(

i
nsur
ance_
idI
NT,

v
ehi
cle_
idI
NT,

t
ype_
of_
insur
anceVARCHAR2(
50)
,

cov
erage_
amountI
NT,

MEMBERFUNCTI
ONi
nsur
ance_
det
ail
sRETURNVARCHAR2

)
;

CREATEORREPLACETYPEBODYI
nsur
anceAS

MEMBERFUNCTI
ONi
nsur
ance_
det
ail
sRETURNVARCHAR2I
S

BEGI
N

RETURN' I
nsur
anceI
D:'||
insurance_i
d||
',Vehi
cleI
D:'
||v
ehi
cle_
id|
|'
,Ty
pe:
'||
t
ype_of
_insur
ance|
|',
Cover
age:'||
cov er
age_amount;

ENDi
nsur
ance_
det
ail
s;

END;

Exampl
eAnony
mousBl
ocksf
orTest
ingEachTy
pe
Vehi
cle
DECLARE

vVehi
cle;

BEGI
N

v:
=Vehi
cle(
1,'
Bus001'
,50)
;

DBMS_
OUTPUT.
PUT_
LINE(
v.di
spl
ay_
det
ail
s);

END;

Fuel
DECLARE

fFuel
;

BEGI
N

f:
=Fuel
(1,
1,TO_
DATE(
'2024-
01-
06'
,'
YYYY-
MM-
DD'
),
50.
00)
;

DBMS_
OUTPUT.
PUT_
LINE(
f.
fuel
_i
nfo)
;

END;

Dr
iver
DECLARE

dDr
iver
;

BEGI
N

d:
=Dr
iver
(1,
'Abdul
haki
m',
'Kamal
'
,953324315,
'123456'
);

DBMS_
OUTPUT.
PUT_
LINE(
d.di
spl
ay_
dri
ver
);

END;
Acci
dent
DECLARE

aAcci
dent
;

BEGI
N

a:
=Acci
dent
(1,1,
TO_
TIMESTAMP(
'2024-
01-
0812:
00:
00'
,'
YYYY-
MM-
DDHH24:
MI:
SS'
),
'
GendeMoode'
);

DBMS_
OUTPUT.
PUT_
LINE(
a.acci
dent
_det
ail
s);

END;

-
-St
aff

DECLARE

sSt
aff
;

BEGI
N

s:
=St
aff
(1,
'Bahar
',
'Hussen'
,'
Comput
erSci
ence'
);

DBMS_
OUTPUT.
PUT_
LINE(
s.di
spl
ay_
staf
f);

END;

Schedul
e
DECLARE

scSchedul
e;

BEGI
N

sc:
=Schedul
e(1,
TO_
DATE(
'08:
00:
00'
,'
HH24:
MI:
SS'
),
TO_
DATE(
'09:
30:
00'
,'
HH24:
MI:
SS'
),
'
Every
day
',1)
;

DBMS_
OUTPUT.
PUT_
LINE(
sc.
schedul
e_det
ail
s);

END;
Mai
ntenance
DECLARE

m Mai
ntenance;

BEGI
N

m:
=Mai
ntenance(
1,1,
TO_
DATE(
'2024-
03-
03'
,'
YYYY-
MM-
DD'
),
'Oi
lChange'
);

DBMS_
OUTPUT.
PUT_
LINE(
m.mai
ntenance_
inf
o);

END;

Tr
ip
DECLARE

tTr
ip;

BEGI
N

t:
=Tri
p(1,
TO_TI
MESTAMP(
'2024-
01-
0208:
30:
00'
,'
YYYY-
MM-
DDHH24:
MI:
SS'
),
'VetCampus'
,
'
MainCampus',
1);

DBMS_
OUTPUT.
PUT_
LINE(
t.
tr
ip_
inf
o);

END;

I
nsur
ance
DECLARE

i
Insur
ance;

BEGI
N

i
:=I
nsur
ance(
1,1,
'Ful
lCov
erage'
,50000)
;

DBMS_
OUTPUT.
PUT_
LINE(
i.
insur
ance_
det
ail
s);
END;

Not
es:

1.Repl
aceuser
namewi
tht
heact
ual
userorr
oley
ouwantt
ogr
antpr
ivi
l
egest
o.

2.Ifanytabl
esareref
erenced,
repl
acet
abl
e_namewi
tht
heappr
opr
iat
etabl
enamesandgr
ant
thenecessarypr
ivi
l
eges.

3.Thi
sscri
ptensuresall
typesar
ecreated,methodsar
edef
ined,
andappr
opr
iat
epr
ivi
l
egesar
e
grant
edforexecut
ingandmanagingthetypes.

You might also like