Você está na página 1de 2

CG096 Week 4 Seminar Writing Cursors

PL/SQL CURSORS
In order to perform the following exercises you will need to create a table with columns as shown below: EMPLOYEE: Empid Empname Empgrade Empsalary num er varchar !"#$ number number

Your tas% is to create a procedure which& when evo%ed& will increase the salary for an employee by '"## or '(### depending on his or her grade !the higher the grade& the higher the employee)s ran%ing within the company$* You will need to populate the table first with a minimum of (# entries& the empgrade value of which should be between ( and "* + script file Create!Emp"s#$ is provided on ,lac%board for this purpose* -he code overleaf will provide a s%eleton for the procedure& but you will need to fill in the missing bits indicated by o$d letters* You are recommended to use .otepad to do the editing& and you will need to give your file the extension "s#$& e.g* calling it sa$ar%!in&rease"s#$* Once you have done this& you should attempt to compile the code by means of the ' command !using the full path/name of the file$ in 01L2Plus* If Oracle tells you that the procedure has been compiled with errors& entering the command s(o) errors will list the problems with the code* Once the procedure has compiled successfully& you can run it by typing e*e&ute sa$ar%!in&rease at the 01L3 prompt* .O-E0: 4emember that you need to have a variable to store each component of the return from the cursor* 5here an I6 statement is used& remember to E.7 I68 -he salaries for the grades are listed overleaf:

Grade ( ; 9 " E*er&ise +,

Sa$ar% Range (####/("### (9###/(:"## (:###/ ### ("##/ ""## "###/;####

<omplete the code below& including a cursor which will select the grade& salary and employee id for each record* You should then use this information to chec% the grade and increase the salary accordingly* -he criteria for increase are given in the pseudocode below* <4E+-E O4 4EPL+<E P4O<E7=4E salary>increase +0 /- .e&$are t(e &ursor and /aria $es (ere )it(out .ECL0RE -/ ,E?I. /- Open t(e &ursor -/ LOOP 6E-<@ A2 &omp$ete t(e 1et&( &ommand -/ EBI- 5@E. &ursor!nameC.O-6O=.78 A2this will exit when cursor empty2A A2 C(e&k using i1 statement, i1 grade is 2 4 in&rease sa$ar% % 300 C(e&k using i1 statement, i1 grade is 4 5 in&rease sa$ar% % +000 -/ E.7 LOOP8 E.78 Once this is completed& compile the code and correct any errors that are noted* Execute the procedure and note the changes to the salary* E*er&ise 6, +mend the code so that if the salary increase would ta%e the salary above the maximum for that grade& the salary is altered to the maximum and not increased above it* !.O-E: you may wish to create a ?rade table for this tas%$*

Você também pode gostar