Q1. Evaluate each of the following following declarations. declarations. Determine Determine which of them are legal / not legal and explain why. a. DECLAE v!id "#$%E&'() *. DECLAE v!x+ v!y+ v!, -ACA&10() c. DECLAE v!*irthdate DAE DAE "2 "#LL) d. DECLAE v!in!stoc3 %22LEA" 45 1) Ans1. a( -alid -alid *( "ot -alid 6 we can7t declare multiple varia*les at once. c( "ot -alid6 -alid6 we we must assign a value. d("ot -alid 6 we have to write %22LEA" 45 rue) 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q Create a *loc3 that declares two varia*les. Assign the value of these 8L/9QL varia*les to i9QL:8lus host varia*les and print the results of the 8L/9QL varia*les to the screen. Execute your 8L/9QL *loc3. 9ave your 8L/9QL *loc3 in a file named p1;'.s;l+ *y clic3ing the 9ave 9cript *utton. emem*er to save the script with a .s;l extension. -!CA Character &varia*le length( -!"#$ "um*er Assign values to these varia*les as follows4 -aria*le -alue 6666666666 6666666666666666666666666666666666666666 -!CA he literal <' is the answer< -!"#$ he first two characters from -!CA Ans. 9QL= varia*le v! char varchar&>0( varchar&>0( 9QL= varia*le v!num "um*er %egin 4v!char457' is the answer7) 4v!num45') end) 9Ql= print v!char) 9Ql=print v!num) 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q > DECLAE v!weight "#$%E&>( 45 ?00) v!message -ACA&@@( 45 <8roduct 1001<) %EB" /:9#%%L2C:/ DECLAE v!weight "#$%E&>( 45 1) v!message -ACA&@@( 45 <8roduct 11001<) 11001<) v!new!locn -ACA&@0( 45
E"D) v!weight 45 v!weight 1) v!message 45 v!message FF < is in stoc3<) v!new!locn 45 <estern < FF v!new!locn) E"D)/ Evaluate the 8L/9QL *loc3 a*ove and determine the data type and value of each of the following varia*les according to the 8L/9QL rules. a(he value of -!EB at position 1 is4 *(he value of -!"E!L2C" at position 1 is4 c( he value of -!EB at position is4 d(he value of -!$E99AE at position is4 e(he value of -!"E!L2C" at position is4 Ans>. a. he datatype is a num*er. *. estern Europe he datatype is a num*er. c. ?01 he datatype is a num*er. d. 8roduct 1001 is in stoc3. he datatype is a num*er. e.Bllegal -!"E!L2C" is not visi*le outside the su**loc3. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q ' Consider the structure of following ta*les structure E$8L2GEE9 HE$8L2GEE!BD +IB9!"A$E+ LA9!"A$E + E$ABL + 82"E!"#$%E +BE!DAE+ J2%!BD+ 9ALAG + C2$$B99B2"!8C +A"AE!BD + DE8A$E"!BD K
a(Create a uni;ue listing of all o*s that are in department >0. Bnclude the location of department M0 in the output. *(rite a ;uery to display the employee last name+ department name+ location BD+ and city of all employees who earn a commission. Ans'. a(9ELEC DB9B"C o*!id+ location!id I2$ employees+ departments EE employees.department!id 5 departments.department!id A"D employees.department!id 5 N0) *(9ELEC e.last!name+ d.department!name+ d.location!id+ l.c ity I2$ employees e+ departments d+ locations l EE e.department!id 5 d.department!id A"D d.location!id 5 l.location!id A"D e.commission!pct B9 "2 "#LL)
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q5. rite a 8L/9QL *loc3 to delete all employees whose o* 57CLE7 and update the E$8 file with o* 5 OCA8AB"7 and sal 5 N000. And chec3 if any rows have *een processed. #se the 9QL P"2I2#"D attri*ute. Bf it is true the 2LL%AC if it is IAL9E then commit. Ans@. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q?. Declare a cursor that select all students in a given section and raise the C8A *y .0@P and updates the ta*le and also updates another ta*le which 3eeps trac3 of the raised C8A. Ans?. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q. rite a *loc3 which users a Cursor I2 loop to select the five highest earners from the E$8 ta*le and write their details to the $E99AE9 ta*le. esults should loo3 in the following manner4 Ans. set serveroutput on) Declare v num*er&10(45Rv) empno emp.empnoPtype) ename emp.enamePtype) sal emp.salPtype) cursor cur!sal Bs select distinct empno + ename + sal from emp order *y sal %egin 2pen cur!sal) L228 Ietch cur!sal into empno+ ename + sal) exit when cur!sal P"2I2#"D) exit when &cur!salProwcount=v() d*ms!output.put!line&empnoFF7 OFFenameFF7 OFFempno FF7 SFFsalFF() end loop) close cur!sal) end4 / 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 QN. rite a 8L/9QL *loc3 to delete all employees *elonging to the department @0 and chec3 if atleast one row has *een processed. #se the 9QLPI2#"D attri*ute. Bnsert the value into a ta*le del!history and give the result. AnsN. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 QM. Create and execute a 8L/9QL *loc3 that accepts two num*ers through i9QL:8lus su*stitution varia*les. a. #se the DEIB"E command to provide the two values. DEIB"E p!num1 5 DEIB"E p!num 5 ' *. 8ass the two values defined in step a a*ove+ to the 8L/9QL *loc3 through i9QL:8lus su*stitution varia*les. he first num*er should *e divided *y the second num*er and have
the second num*er added to the result. he result should *e stored in a 8L/9QL varia*le and printed on the screen. "ote4 9E -EBIG 2II in the 8L/9QL *loc3. ' AnsM. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q10. %uild a 8L/9QL *loc3 that computes the total compensation for one year. a. he annual salary and the annual *onus percentage values are defined using the DEIB"E command. *. 8ass the values defined in the a*ove step to the 8L/9QL *loc3 through i9QL:8lus su*stitution varia*les. he *onus must *e converted from a whole num*er to a decimal &for example+ 1@ to .1@(. Bf the salary is null+ set it to ,ero *efore computing the total compensation. Execute the 8L/9QL *loc3. eminder4 #se the "-L function to handle null values. "ote4 otal compensation is the sum of the annual salary and the annual *onus. o test the "-L function+ set the DEIB"E varia*le e;ual to "#LL. DEIB"E p!salary 5 @0000 DEIB"E p!*onus 5 1 Ans10. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q11. $odify the 8L/9QL *loc3 you created in exercise 1 to insert a new department into the DE8A$E"9 ta*le. a. #se the DEIB"E command to provide the department name. "ame the new department Education. *. 8ass the value defined for the department name to the 8L/9QL *loc3 through a i9QL:8lus su*stitution varia*le. ather than printing the department num*er retrieved from exercise 1+ add 10 to it and use it as the department num*er for the new department. c. Leave the location num*er as null for now. d. Execute the 8L/9QL *loc3. e. Display the new department that you created. Ans11. 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q1. Create a 8L/9QL *loc3 that computes the commission amount for a given employee *ased on the employee7s salary. a. #se the DEIB"E command to provide the employee BD. 8ass the value to the 8L/9QL *loc3 through a i9QL:8lus su*stitution varia*le. DEIB"E p!empno 5 100 *. Bf the employee7s salary is less than T@+000+ display the *onus amount for the employee as 10P of the salary. c. Bf the employee7s salary is *etween T@+000 and T10+000+ display the *onus amount for the employee as 1@P of the salary. d. Bf the employee7s salary exceeds T10+000+ display the *onus amount for the employee as 0P of the salary. e. Bf the employee7s salary is "#LL+ display the *onus amount for the employee as 0. f. est the 8L/9QL *loc3 for each case using the following test cases+ and chec3 each *onus amount. Ans1. E"
9ELEC sal
CA9E U
@000
E" E"
sal sal
%EEE"
E" E"
: @000
E" E"
A"D
sal sal
: =
sal sal
E" E"D
.1 .1@ 10000
: B9
10000
. "#LL 0 *onus+
sal I2$ emp)
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q1>. Create a 8L/9QL *loc3 that rewards an employee *y appending an asteris3 in the 9A9 column for every T1000 of the employee7s salary. 9ave your 8L/9QL *loc3 in a file called p';'.s;l *y clic3ing on the 9ave 9cript *utton. emem*er to save the script with a .s;l extension. a. #se the DEIB"E command to provide the employee BD. 8ass the value to the 8L/9QL *loc3 through a i9QL:8lus su*stitution varia*le. DEIB"E p!empno510' *. Bnitiali,e a v!asteris3 varia*le that contains a "#LL. c. Append an asteris3 to the string for every T1000 of the salary amount. Ior example+ if the employee has a salary amount of TN000+ the string of asteris3s should contain eight asteris3s. Bf the employee has a salary amount of T1@00+ the string of asteris3s should contain 1> asteris3s. d. #pdate the 9A9 column for the employee with the string of asteris3s. e. Commit. f. est the *loc3 for the following values4 DEIB"E p!empno51' DEIB"E p!empno51? g. Display the rows from the E$8 ta*le to verify whether your 8L/9QL *loc3 has executed successfully Ans1>. a. *. c.
E"D L228) g.9ELEC employee!id + salary + stars I2$ emp where emplo yee!id 5 1?) 6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 Q1'. $odify the *loc3 you created in practice to retrieve all information a*out each department from the DE8A$E"9 ta*le and print the information to the screen+ incorporating an B"DEV %G ta*le of records. a. Declare an B"DEV %G ta*le+ $G!DE8!A%LE+ to temporarily store the num*er+ name+ and location of all the departments. *. #sing a loop+ retrieve all department information currently in the DE8A$E"9 ta*le and store it in the B"DEV %G ta*le. #se the following ta*le to assign the value for DE8A$E"!BD *ased on the value of the counter used in the loop. Exit the loop when the counter reaches the value . c. #sing another loop+ retrieve the department information from the B"DEV %G ta*le and print it to the screen. C2#"E DE8A$E"!BD 1 10 0 > @0 ' ?0 @ N0 ? M0 110 Ans1'. 9E 9E-E2#8# 2" DECLAE G8E DeptBD B9 A%LE 2I "#$%E&'( B"DEV %G %B"AG!B"EE) G8E Dept"ame B9 A%LE 2I -ACA&>0( B"DEV %G %B"AG!B"EE) G8E DeptLocation B9 A%LE 2I "#$%E&'( B"DEV %G %B"AG!B"EE) G8E $G!DE8!A%LE B9 A%LE 2I departmentsP2G8E B"DEV %G %B"AG!B"EE) Depta*le $G!DE8!A%LE) EmpBd DeptBD) Emp"ame Dept"ame) EmpLocation DeptLocation) %EB" 9ELEC department!id+department!name+location!id %#L C2LLEC B"2 EmpBd+Emp"ame+EmpLocation I2$ departments) I2 B" EmpBd.IB9..EmpBd.LA9 L228 D%$9!2#8#.8#!LB"E&
6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666