Technical Assessment 2 GisonMark

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Database System with

Administration

TECHNICAL ASSESSMENT

2
M4, M5, M6, M7

Name: GISON,MARK

Section: TR31

Professor:

Database System with Page 1


Administration of 4
REQUIREMENTS:
• Screen shots (use snipping tool) of your code and output from SQL Developer.
• Paste your screen shots / answers after each question.

PART-1. M4-PROCEDURES (10 Points)

1. Write a procedure that displays the number of countries in a given region (prompt for value)
whose highest elevations exceed a given value (prompt for value). The procedure should accept
two formal parameters, one for a region_id and the other for an elevation value for comparison.
Use DBMS_OUTPUT.PUT_LINE to display the results in a message. Test your procedure using the
value 5 for the region_id and 2000 for the highest elevation.

PART-2. M5-FUNCTIONS (10 Points)

1. Create a function called full_name. Pass two parameters to the function, an employee’s last name
and first name. The function should return the full name in the format, last name, comma, space,
Database System with Page 2
Administration of 4
first name (for example: Smith, Joe). (3pts)

Test your function from an anonymous block which uses a local variable to store and display the
returned value.(2pts)

2. Modify your anonymous block from the previous step to remove the local variable declaration
and call the function directly from within the DBMS_OUTPUT.PUT_LINE call. Test the block
again.(2pts)

Database System with Page 3


Administration of 4
3. Now call the function from within a SELECT statement, not a PL/SQL block. Your SELECT statement
should display the first_name, last_name, and full name (using the function) of all employees in
department 50. (3pts)

PART-3. M6-PACKAGES (20 Points)

A. Create a package specification and body called JOB_PKG, containing the following procedures:
• Create a procedure called ADD_JOB to insert a new job into the JOBS table. The procedure has
job id, job title, minimum salary and maximum salary as parameters. Ensure that the value of
maximum salary is greater than minimum salary, raise an exception if this rule is violated (create
a private procedure for salary validation). (10 pts)

Database System with Page 4


Administration of 4
• Create a procedure called UPD_JOB to update the job title. Provide the job ID and a new title
using two parameters. Include the necessary exception handling if no update occurs. (4 pts)

Database System with Page 5


Administration of 4
B. Create an anonymous block.
• Invoke your ADD_JOB package procedure by passing the values IT_SYSAN and
SYSTEMS ANALYST as parameters. Values for minimum and maximum salary are 10000 and
5000 respectively. (2 pts)
• Invoke your ADD_JOB package procedure by passing the values IT_DBADM and
DATABASE ADMINISTRATOR as parameters. Values for minimum and maximum salary are 5000
and 10000 respectively. (2 pts)
• Invoke your UPD_JOB package procedure by passing the values IT_DBADM and
DATABASE ADMINISTRATOR as parameters. (2 pts)

PART-4. M7-TRIGGERS (20 Points)

A. The rows in the JOBS table store a minimum and maximum salary allowed for different JOB_ID
values. You are asked to write code to ensure that employees’ salaries fall in the range allowed for
their job type, for insert and update operations.
Database System with Page 6
Administration of 4
Create a procedure called CHECK_SALARY as follows:
▪ The subprogram accepts two parameters, one for an employee’s job ID string and the
other for the salary. (2 pts)
▪ The procedure uses the job ID to determine the minimum and maximum salary for the
specified job. (2 pts)
• If the salary parameter does not fall within the salary range of the job, inclusive of the
minimum and maximum, then it should raise an application exception, with the message
“Invalid salary <sal>. Salaries for job <jobid> must be between <min> and <max>”.
Replace the various items in the message with values supplied by parameters and
variables populated by queries. (6 pts)

Note: Submit a complete snip of the procedure. Ensure to follow the given procedure
specifications.
\

B. Create a trigger called CHECK_SALARY_TRG on the EMPLOYEES table that fires before an INSERT or
UPDATE operation on each row: (5 pts)

• The trigger must call the CHECK_SALARY procedure to carry out the business logic.
• The trigger should pass the new job ID and salary to the procedure parameters.

Note: Submit a complete snip of the trigger code. Ensure to follow the given trigger
specifications.

Database System with Page 7


Administration of 4
C. Create an anonymous block to insert a new record in employees table with employee id as 777, job
id as IT_DBADM, salary as 20000. (5 pts)

Note: Submit a complete snip of the anonymous block and output.

Database System with Page 8


Administration of 4

You might also like