Practice 5 Practice 12
Practice 5 Practice 12
Practice 12
1. Modify the code for the EMP_PKGpackage that you created in Practice 4 step 2, and overload the
ADD_EMPLOYEEprocedure.
a. In the package specification, add a new procedure called ADD_EMPLOYEEthat accepts the following
three parameters:
i. First name
ii. Last name
iii. Department ID
b. Click un !cript to create the package. Compile the package.
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
45 A%%_emplo&ee 54
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
E6$ emp_p!3
4
#7O8 ERROR#
c. Implement the new ADD_EMPLOYEE procedure in the package body as follows:
i. Format the email address in uppercase characters, using the first letter of the first name
concatenated with the first se"en letters of the last name.
ii. #he procedure should call the e$isting %DD&'M(L)*'' procedure to perform the actual
I+!'# operation using its parameters and formatted email to supply the "alues.
iii. Click un !cript to create the package. Compile the package.
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21) "#
9EG"6
"- :ali%_%epti%(p_%epti%) T7E6
"6#ERT "6TO emplo&ees(emplo&ee_i%+ 'irst_name+ last_name+ email+
,ob_i%+ mana!er_i%+ ;ire_%ate+ salar&+ commission_pct+ %epartment_i%)
<ALUE# (emplo&ees_se=(6E>T<AL+ p_'irst_name+ p_last_name+ p_email+
p_,ob+ p_m!r+ TRU6C(#*#$ATE)+ p_sal+ p_comm+ p_%epti%)3
EL#E
RA"#E_APPL"CAT"O6_ERROR (?2121/+ ."n:ali% %epartment "$( Tr& a!ain(.)3
E6$ "-3
E6$ a%%_emplo&ee3
45 6e@ o:erloa%e% a%%_emplo&ee proce%Are 54
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE) "#
p_email emplo&ees(email)t&pe3
9EG"6
p_email BC UPPER(#U9#TR(p_'irst_name+ 1+ 1)DD#U9#TR(p_last_name+ 1+ E))3
a%%_emplo&ee(p_'irst_name+ p_last_name+ p_email+ p_%epti% CF p_%epti%)3
E6$3
45 En% %eclaration o' t;e o:erloa%e% a%%_emplo&ee proce%Are 54
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE) "#
9EG"6
#ELECT salar&+ ,ob_i%
"6TO p_sal+ p_,ob
-ROG emplo&ees
87ERE emplo&ee_i% C p_empi%3
E6$ !et_emplo&ee3
E6$ emp_p!3
4
#7O8 ERROR#
d. In"oke the new ADD_EMPLOYEEprocedure using the name Samuel Joplinto be added to
department 30.
E>ECUTE emp_p!(a%%_emplo&ee(.#amAel.+ .Hoplin.+ 21)
e. Confirm that the new employee was added to the EMPLOYEEStable.
#ELECT 5
-ROG emplo&ees
87ERE last_name C .Hoplin.3
,. In the EMP_PKGpackage, create two overloaded functions called GET_EMPLOYEE:
a. In the package specification, add the following functions-
i. #he .'#&'M(L)*'' function that accepts the parameter called p&emp&id based on the
employees.employee&id/#*(' type. #his function should return an 'M(L)*''!/)0#*('.
ii. #he .'#&'M(L)*'' function that accepts the parameter called p&family&name of type
employees.last&name/#*('. #his function should return an 'M(L)*''!/)0#*('.
b. Click the un !cript 1F23 icon to re-create the package. Compile the package.
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
45 6e@ o:erloa%e% !et_emplo&ees 'Anctions specs starts ;ereB 54
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe3
45 6e@ o:erloa%e% !et_emplo&ees 'Anctions specs en%s ;ere( 54
E6$ emp_p!3
4
#7O8 ERROR#
c. n the package body:
i. Implement the first .'#&'M(L)*'' function to 4uery an employee using the employee5s ID.
ii. Implement the second .'#&'M(L)*'' function to use the e4uality operator on the "alue
supplied in the p& family&name parameter.
d. Click !un "cript to re-create the package. Compile the package.
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
45 6e@ o:erloa%e% !et_emplo&ees 'Anctions specs starts ;ereB 54
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe3
45 6e@ o:erloa%e% !et_emplo&ees 'Anctions specs en%s ;ere( 54
E6$ emp_p!3
4
#7O8 ERROR#
CREATE OR REPLACE PACKAGE 9O$* emp_p! "#
-U6CT"O6 :ali%_%epti%(p_%epti% "6 %epartments(%epartment_i%)T*PE) RETUR6
9OOLEA6 "#
:_%Amm& PL#_"6TEGER3
9EG"6
#ELECT 1
"6TO :_%Amm&
-ROG %epartments
87ERE %epartment_i% C p_%epti%3
RETUR6 TRUE3
E>CEPT"O6
87E6 6O_$ATA_-OU6$ T7E6
RETUR6 -AL#E3
E6$ :ali%_%epti%3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21) "#
9EG"6
"- :ali%_%epti%(p_%epti%) T7E6
"6#ERT "6TO emplo&ees(emplo&ee_i%+ 'irst_name+ last_name+ email+
,ob_i%+ mana!er_i%+ ;ire_%ate+ salar&+ commission_pct+ %epartment_i%)
<ALUE# (emplo&ees_se=(6E>T<AL+ p_'irst_name+ p_last_name+ p_email+
p_,ob+ p_m!r+ TRU6C(#*#$ATE)+ p_sal+ p_comm+ p_%epti%)3
EL#E
RA"#E_APPL"CAT"O6_ERROR (?2121/+ ."n:ali% %epartment "$( Tr& a!ain(.)3
E6$ "-3
E6$ a%%_emplo&ee3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE) "#
p_email emplo&ees(email)t&pe3
9EG"6
p_email BC UPPER(#U9#TR(p_'irst_name+ 1+ 1)DD#U9#TR(p_last_name+ 1+ E))3
a%%_emplo&ee(p_'irst_name+ p_last_name+ p_email+ p_%epti% CF p_%epti%)3
E6$3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE) "#
9EG"6
#ELECT salar&+ ,ob_i%
"6TO p_sal+ p_,ob
-ROG emplo&ees
87ERE emplo&ee_i% C p_empi%3
E6$ !et_emplo&ee3
45 6e@ !et_emplo&ee 'Anction %eclaration starts ;ere 54
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE emplo&ee_i% C p_emp_i%3
RETUR6 rec_emp3
E6$3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE last_name C p_'amil&_name3
RETUR6 rec_emp3
E6$3
45 6e@ o:erloa%e% !et_emplo&ee 'Anction %eclaration en%s ;ere 54
E6$ emp_p!3
4
#7O8 ERROR#
Practice 12 (continued)
e. %dd a utility procedure PRINT_EMPLOYEEto the EMP_PKGpackage as follows:
i. #he procedure accepts an 'M(L)*''!/)0#*(' as a parameter.
ii. #he procedure displays the following for an employee on one line, using the D6M!&)7#(7#
package-
-department#id
-employee#id
-first#name
-last#name
-$ob#id
-salary
f. Click un !cript to re-create the package. Compile the package.
-- Package "P%C&C'()*
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe3
45 6e@ print_emplo&ee print_emplo&ee proce%Are spec 54
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe)3
E6$ emp_p!3
4
#7O8 ERROR#
?? Paca!e 9O$*
CREATE OR REPLACE PACKAGE 9O$* emp_p! "#
-U6CT"O6 :ali%_%epti%(p_%epti% "6 %epartments(%epartment_i%)T*PE) RETUR6 9OOLEA6 "#
:_%Amm& PL#_"6TEGER3
9EG"6
#ELECT 1
"6TO :_%Amm&
-ROG %epartments
87ERE %epartment_i% C p_%epti%3
RETUR6 TRUE3
E>CEPT"O6
87E6 6O_$ATA_-OU6$ T7E6
RETUR6 -AL#E3
E6$ :ali%_%epti%3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21) "#
9EG"6
"- :ali%_%epti%(p_%epti%) T7E6
"6#ERT "6TO emplo&ees(emplo&ee_i%+ 'irst_name+ last_name+ email+
,ob_i%+ mana!er_i%+ ;ire_%ate+ salar&+ commission_pct+ %epartment_i%)
<ALUE# (emplo&ees_se=(6E>T<AL+ p_'irst_name+ p_last_name+ p_email+
p_,ob+ p_m!r+ TRU6C(#*#$ATE)+ p_sal+ p_comm+ p_%epti%)3
EL#E
RA"#E_APPL"CAT"O6_ERROR (?2121/+ ."n:ali% %epartment "$( Tr& a!ain(.)3
E6$ "-3
E6$ a%%_emplo&ee3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE) "#
p_email emplo&ees(email)t&pe3
9EG"6
p_email BC UPPER(#U9#TR(p_'irst_name+ 1+ 1)DD#U9#TR(p_last_name+ 1+ E))3
a%%_emplo&ee(p_'irst_name+ p_last_name+ p_email+ p_%epti% CF p_%epti%)3
E6$3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE) "#
9EG"6
#ELECT salar&+ ,ob_i%
"6TO p_sal+ p_,ob
-ROG emplo&ees
87ERE emplo&ee_i% C p_empi%3
E6$ !et_emplo&ee3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE emplo&ee_i% C p_emp_i%3
RETUR6 rec_emp3
E6$3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE last_name C p_'amil&_name3
RETUR6 rec_emp3
E6$3
45 6e@ print_emplo&ees proce%Are %eclaration( 54
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe) "#
9EG"6
$9G#_OUTPUT(PUT_L"6E(p_rec_emp(%epartment_i% DD. .DD
p_rec_emp(emplo&ee_i%DD. .DD
p_rec_emp('irst_nameDD. .DD
p_rec_emp(last_nameDD. .DD
p_rec_emp(,ob_i%DD. .DD
p_rec_emp(salar&)3
E6$3
E6$ emp_p!3
4
#7O8 ERROR#
g. +se an anonymous block to invoke the EMP_PKG.GET_EMPLOYEEfunction with an employee ,
of 100and family name of Joplin. +se the PRINT_EMPLOYEEprocedure to display the results for
each row returned.
9EG"6
emp_p!(print_emplo&ee(emp_p!(!et_emplo&ee(111))3
emp_p!(print_emplo&ee(emp_p!(!et_emplo&ee(.Hoplin.))3
E6$3
4
8. -ecause the company does not fre.uently change its departmental data, you can improve the
performance of your EMP_PKGby adding a public procedure, INIT_DEPARTMENTS, to populate a
private P/0"1/ table of valid department ,s. 2odify the !ALID_DEPTIDfunction to use the
private P/0"1/ table contents to validate department , values.
6oteB (he "ol_0#_03."$lsolution file script contains the code for steps a, b, and c.
a. In the package specification, create a procedure called INIT_DEPARTMENTSwith no parameters by
adding the following to the package specification section before the
PRINT_EMPLOYEESspecification:
P!)C%,+!% init#departments3
b. In the package body, implement the INIT_DEPARTMENTSprocedure to store all department ,s in
a private P/0"1/ inde4-by table named %ali&_&epa'(men("containing )OOLEANvalues.
i. Declare the valid#departments "ariable and its type definition boolean#tab#type before all procedures
in the body. 'nter the following at the beginning of the package body-
(5P% boolean#tab#type " ('-/% )& -))/%'*
*,%6 -5 -*'!5#*(%7%!3
valid#departments boolean#tab#type3
Practice 12 (continAe%)
ii. 7se the department#id column "alue as the inde$ to create the entry in the inde$9by table to indicate its
presence, and assign the entry a "alue of (!+%. 'nter the *(#,%P'!(2%*(" procedure declaration
at the end of the package body 1right after the print#employees procedure3 as follows-
P!)C%,+!% init#departments "
-%7*
&)! rec * 8"%/%C( department#id &!)2 departments9 /))P
valid#departments8rec.department#id9 :: (!+%3
%*, /))P3
%*,3
c. n the body, create an initiali;ation block that calls the INIT_DEPARTMENTSprocedure to
initiali;e the table as follows:
-%7* init#departments3 %*,3
d. Click !un "cript to create the package. Compile the package.
?? Paca!e #PEC"-"CAT"O6
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe3
45 6e@ proce%Are init_%epartments spec 54
PROCE$URE init_%epartments3
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe)3
E6$ emp_p!3
4
#7O8 ERROR#
?? Paca!e 9O$*
CREATE OR REPLACE PACKAGE 9O$* emp_p! "#
45 6e@ t&pe 54
T*PE boolean_tab_t&pe "# TA9LE O- 9OOLEA6
"6$E> 9* 9"6AR*_"6TEGER3
:ali%_%epartments boolean_tab_t&pe3
-U6CT"O6 :ali%_%epti%(p_%epti% "6 %epartments(%epartment_i%)T*PE) RETUR6 9OOLEA6 "#
:_%Amm& PL#_"6TEGER3
9EG"6
#ELECT 1
"6TO :_%Amm&
-ROG %epartments
87ERE %epartment_i% C p_%epti%3
RETUR6 TRUE3
E>CEPT"O6
87E6 6O_$ATA_-OU6$ T7E6
RETUR6 -AL#E3
E6$ :ali%_%epti%3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21) "#
9EG"6
"- :ali%_%epti%(p_%epti%) T7E6
"6#ERT "6TO emplo&ees(emplo&ee_i%+ 'irst_name+ last_name+ email+
,ob_i%+ mana!er_i%+ ;ire_%ate+ salar&+ commission_pct+ %epartment_i%)
<ALUE# (emplo&ees_se=(6E>T<AL+ p_'irst_name+ p_last_name+ p_email+
p_,ob+ p_m!r+ TRU6C(#*#$ATE)+ p_sal+ p_comm+ p_%epti%)3
EL#E
RA"#E_APPL"CAT"O6_ERROR (?2121/+ ."n:ali% %epartment "$( Tr& a!ain(.)3
E6$ "-3
E6$ a%%_emplo&ee3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE) "#
p_email emplo&ees(email)t&pe3
9EG"6
p_email BC UPPER(#U9#TR(p_'irst_name+ 1+ 1)DD#U9#TR(p_last_name+ 1+ E))3
a%%_emplo&ee(p_'irst_name+ p_last_name+ p_email+ p_%epti% CF p_%epti%)3
E6$3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE) "#
9EG"6
#ELECT salar&+ ,ob_i%
"6TO p_sal+ p_,ob
-ROG emplo&ees
87ERE emplo&ee_i% C p_empi%3
E6$ !et_emplo&ee3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE emplo&ee_i% C p_emp_i%3
RETUR6 rec_emp3
E6$3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE last_name C p_'amil&_name3
RETUR6 rec_emp3
E6$3
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe) "#
9EG"6
$9G#_OUTPUT(PUT_L"6E(p_rec_emp(%epartment_i% DD. .DD
p_rec_emp(emplo&ee_i%DD. .DD
p_rec_emp('irst_nameDD. .DD
p_rec_emp(last_nameDD. .DD
p_rec_emp(,ob_i%DD. .DD
p_rec_emp(salar&)3
E6$3
45 6e@ init_%epartments proce%Are %eclaration( 54
PROCE$URE init_%epartments "#
9EG"6
-OR rec "6 (#ELECT %epartment_i% -ROG %epartments)
LOOP
:ali%_%epartments(rec(%epartment_i%) BC TRUE3
E6$ LOOP3
E6$3
45 call t;e ne@ init_%epartments proce%Are( 54
9EG"6
init_%epartments3
E6$ emp_p!3
4
#7O8 ERROR#
4. Change the !ALID_DEPTIDvalidation processing function to use the private P/0"1/ table of
department ,s.
a. 2odify the <'/,#,%P(, function to perform its validation by using the P/0"1/ table of
department , values. Click !un "cript to create the package. Compile the package.
? Paca!e #PEC"-"CAT"O6
CREATE OR REPLACE PACKAGE emp_p! "#
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21)3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE)3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE)3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe3
45 6e@ proce%Are init_%epartments spec 54
PROCE$URE init_%epartments3
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe)3
E6$ emp_p!3
4
#7O8 ERROR#
?? Paca!e 9O$*
CREATE OR REPLACE PACKAGE 9O$* emp_p! "#
T*PE boolean_tab_t&pe "# TA9LE O- 9OOLEA6
"6$E> 9* 9"6AR*_"6TEGER3
:ali%_%epartments boolean_tab_t&pe3
-U6CT"O6 :ali%_%epti%(p_%epti% "6 %epartments(%epartment_i%)T*PE) RETUR6 9OOLEA6 "#
:_%Amm& PL#_"6TEGER3
9EG"6
RETUR6 :ali%_%epartments(eIists(p_%epti%)3
E>CEPT"O6
87E6 6O_$ATA_-OU6$ T7E6
RETUR6 -AL#E3
E6$ :ali%_%epti%3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_email emplo&ees(email)T*PE+
p_,ob emplo&ees(,ob_i%)T*PE $E-AULT .#A_REP.+
p_m!r emplo&ees(mana!er_i%)T*PE $E-AULT 1/0+
p_sal emplo&ees(salar&)T*PE $E-AULT 1111+
p_comm emplo&ees(commission_pct)T*PE $E-AULT 1+
p_%epti% emplo&ees(%epartment_i%)T*PE $E-AULT 21) "#
9EG"6
"- :ali%_%epti%(p_%epti%) T7E6
"6#ERT "6TO emplo&ees(emplo&ee_i%+ 'irst_name+ last_name+ email+
,ob_i%+ mana!er_i%+ ;ire_%ate+ salar&+ commission_pct+ %epartment_i%)
<ALUE# (emplo&ees_se=(6E>T<AL+ p_'irst_name+ p_last_name+ p_email+
p_,ob+ p_m!r+ TRU6C(#*#$ATE)+ p_sal+ p_comm+ p_%epti%)3
EL#E
RA"#E_APPL"CAT"O6_ERROR (?2121/+ ."n:ali% %epartment "$( Tr& a!ain(.)3
E6$ "-3
E6$ a%%_emplo&ee3
PROCE$URE a%%_emplo&ee(
p_'irst_name emplo&ees('irst_name)T*PE+
p_last_name emplo&ees(last_name)T*PE+
p_%epti% emplo&ees(%epartment_i%)T*PE) "#
p_email emplo&ees(email)t&pe3
9EG"6
p_email BC UPPER(#U9#TR(p_'irst_name+ 1+ 1)DD#U9#TR(p_last_name+ 1+ E))3
a%%_emplo&ee(p_'irst_name+ p_last_name+ p_email+ p_%epti% CF p_%epti%)3
E6$3
PROCE$URE !et_emplo&ee(
p_empi% "6 emplo&ees(emplo&ee_i%)T*PE+
p_sal OUT emplo&ees(salar&)T*PE+
p_,ob OUT emplo&ees(,ob_i%)T*PE) "#
9EG"6
#ELECT salar&+ ,ob_i%
"6TO p_sal+ p_,ob
-ROG emplo&ees
87ERE emplo&ee_i% C p_empi%3
E6$ !et_emplo&ee3
-U6CT"O6 !et_emplo&ee(p_emp_i% emplo&ees(emplo&ee_i%)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE emplo&ee_i% C p_emp_i%3
RETUR6 rec_emp3
E6$3
-U6CT"O6 !et_emplo&ee(p_'amil&_name emplo&ees(last_name)t&pe)
retArn emplo&ees)ro@t&pe "#
rec_emp emplo&ees)ro@t&pe3
9EG"6
#ELECT 5 "6TO rec_emp
-ROG emplo&ees
87ERE last_name C p_'amil&_name3
RETUR6 rec_emp3
E6$3
PROCE$URE print_emplo&ee(p_rec_emp emplo&ees)ro@t&pe) "#
9EG"6
$9G#_OUTPUT(PUT_L"6E(p_rec_emp(%epartment_i% DD. .DD
p_rec_emp(emplo&ee_i%DD. .DD
p_rec_emp('irst_nameDD. .DD
p_rec_emp(last_nameDD. .DD
p_rec_emp(,ob_i%DD. .DD
p_rec_emp(salar&)3
E6$3
45 6e@ init_%epartments proce%Are %eclaration( 54
PROCE$URE init_%epartments "#
9EG"6
-OR rec "6 (#ELECT %epartment_i% -ROG %epartments)
LOOP
:ali%_%epartments(rec(%epartment_i%) BC TRUE3
E6$ LOOP3
E6$3
45 call t;e ne@ init_%epartments proce%Are( 54
9EG"6
init_%epartments3
E6$ emp_p!3
4
#7O8 ERROR#
b. (est your code by calling ',,#%2P/)5%% using the name =ames -ond in department
>?. @hat happensA
E>ECUTE emp_p!(a%%_emplo&ee(.Hames.+ .9on%.+ 10)
c. nsert a new department. "pecify >? for the department , and "ecurity for the department
name. Commit and verify the changes.
d. #est your code again, by calling ADD_EMPLOYEEusing the name Jame" )on&in department >?.
@hat h appensA
e. '$ecute the EMP_PKG.INIT_DEPARTMENTSprocedure to update the internal P/0"1/ table with
the latest departmental data.
f. #est your code by calling ADD_EMPLOYEEusing the employee name Jame" )on&, who works in
department >?. @hat happensA
g. ,elete employee Jame" )on&and department >? from their respective tables, commit the
changes, and refresh the department data by invoking the
EMP_PKG.INIT_DEPARTMENTSprocedure.
Practice 12 (continAe%)
?. !eorgani;e the subprograms in the package specification and the body so that they are in
alphabetical se.uence.
a. %dit the package specification and reorgani;e subprograms alphabetically. Click !un "cript to
re-create the package specification. Compile the package specification. @hat happensA
b. %dit the package body and reorgani;e all subprograms alphabetically. Click !un "cript to re-
create the package specification. !ecompile the package specification. @hat happensA
c. Correct the compilation error using a forward declaration in the body for the appropriate
subprogram reference. Click !un "cript to re-create the package, and then recompile the
package. @hat happensA