0% found this document useful (0 votes)
37 views

Database Task

The document outlines steps to create stored procedures and functions to manipulate data in various database tables. This includes adding new jobs and employee histories, updating job salaries, checking if employees exceed average salaries, and retrieving an employee's years of service and number of different jobs worked.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Database Task

The document outlines steps to create stored procedures and functions to manipulate data in various database tables. This includes adding new jobs and employee histories, updating job salaries, checking if employees exceed average salaries, and retrieving an employee's years of service and number of different jobs worked.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Entity Relationship Diagram:

Based on the below ER diagram.

1. create a program to add a new job into the JOBS table.


a. Create a stored procedure called NEW_JOB to enter a new order into the
JOBS table. The procedure should accept three parameters. The first and
second parameters supply a job ID and a job title. The third parameter
supplies the minimum salary. Use the maximum salary for the new job as
twice the minimumsalary supplied for the job ID.
b. Invoke the procedure to add a new job with job ID 'SY_ANAL', job title
'System Analyst', and minimum salary of 6000.
c. Check whether a row was added and note the new job ID for use in
the nextexercise. Commit the changes.
2. create a program to add a new row to the JOB_HISTORY table, for an
existing employee.
a. Create a stored procedure called ADD_JOB_HIST to add a new row into
the JOB_HISTORY table for an employee who is changing his job to the
new job ID('SY_ANAL') that you created in exercise 1 b.
The procedure should provide two parameters, one for the employee ID who
is changing the job, and the second for the new job ID. Read the employee ID
fromthe EMPLOYEES table and insert it into the JOB_HISTORY table. Make
the hiredate of this employee as start date and today’s date as end date for
this row in theJOB_HISTORY table.
Change the hire date of this employee in the EMPLOYEES table to today’s
date. Update the job ID of this employee to the job ID passed as parameter (use
the 'SY_ANAL' job ID) and salary equal to the minimum salary for that job
ID + 500.Note: Include exception handling to handle an attempt to insert a
nonexistent employee.
b. Disable all triggers on the EMPLOYEES, JOBS, and JOB_HISTORY tables
beforeinvoking the ADD_JOB_HIST procedure.
c. Execute the procedure with employee ID 106 and job ID
'SY_ANAL' asparameters.
d. Query the JOB_HISTORY and EMPLOYEES tables to view your
changes foremployee 106, and then commit the changes.
e. Reenable the triggers on the EMPLOYEES, JOBS, and JOB_HISTORY tables.
3. create a program to update the minimum and maximum salaries for ajob in the
JOBS table.
a. Create a stored procedure called UPD_JOBSAL to update the minimum and
maximum salaries for a specific job ID in the JOBS table. The procedure
should provide three parameters: the job ID, a new minimum salary, and a
new maximum salary. Add exception handling to account for an invalid job
ID in the JOBS table. Raise an exception if the maximum salary supplied is
less than the minimum salary, and provide a message that will be displayed if
the row in the JOBS table islocked.
b. Execute the UPD_JOBSAL procedure by using a job ID of
'SY_ANAL', aminimum salary of 7000 and a maximum salary of
140.
Note: This should generate an exception message.
c. Disable triggers on the EMPLOYEES and JOBS tables.
d. Execute the UPD_JOBSAL procedure using a job ID of 'SY_ANAL', a
minimumsalary of 7000, and a maximum salary of 14000.
e. Query the JOBS table to view your changes, and then commit the changes.
f. Enable the triggers on the EMPLOYEES and JOBS tables.
4. create a procedure to monitor whether employees have exceeded theiraverage
salaries for their job type.
a. Disable the SECURE_EMPLOYEES trigger.
b. In the EMPLOYEES table, add an EXCEED_AVGSAL column to store up to
threecharacters and a default value of NO. Use a check constraint to allow
the values YES or NO.
c. Write a stored procedure called CHECK_AVGSAL that checks whether each
employee’s salary exceeds the average salary for the JOB_ID. The average
salary for a job is calculated from the information in the JOBS table. If the
employee’s salary exceeds the average for his or her job, then update the
EXCEED_AVGSAL column in the EMPLOYEES table to a value of YES;
otherwise, set the value to NO.Use a cursor to select the employee’s rows
using the FOR UPDATE option in the query. Add exception handling to
account for a record being locked.
Hint: The resource locked/busy error number is –54. Write and use a local
function called GET_JOB_AVGSAL to determine the average salary for a job
IDspecified as a parameter.
d. Execute the CHECK_AVGSAL procedure. Then, to view the results of your
modifications, write a query to display the employee’s ID, job, the average
salary for the job, the employee’s salary and the exceed_avgsal
indicator column foremployees whose salaries exceed the average for their
job, and finally commit the changes.
5. Create a subprogram to retrieve the number of years of service for a specific
employee.
a. Create a stored function called GET_YEARS_SERVICE to retrieve the total
number of years of service for a specific employee. The function should
accept theemployee ID as a parameter and return the number of years of
service. Add error handling to account for an invalid employee ID.
b. Invoke the GET_YEARS_SERVICE function in a call to
DBMS_OUTPUT.PUT_LINE for an employee with ID 999.
c. Display the number of years of service for employee 106 with
DBMS_OUTPUT.PUT_LINE invoking the GET_YEARS_SERVICE function.
d. Query the JOB_HISTORY and EMPLOYEES tables for the specified
employee to verify that the modifications are accurate. The values
represented in the results on this page may differ from those you get when
you run these queries.
6. create a program to retrieve the number of different jobs that an employee
worked on during his or her service.
a. Create a stored function called GET_JOB_COUNT to retrieve the total
number ofdifferent jobs on which an employee worked.
The function should accept the employee ID in a parameter, and return the
number of different jobs that the employee worked on until now, including
the present job. Add exception handling to account for an invalid employee
ID.
Hint: Use the distinct job IDs from the JOB_HISTORY table, and exclude
the current job ID, if it is one of the job IDs on which the employee has
already worked. Write a UNION of two queries and count the rows retrieved
into a PL/SQLtable. Use a FETCH with BULK COLLECT INTO to obtain the
unique jobs for the employee.
b. Invoke the function for the employee with the ID of 176.

You might also like