Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PL / SQL help needed. I ' m using SQL developer. Here is the question below: 2 . But Money Doesn t Grow on Trees

PL/SQL help needed. I'm using SQL developer. Here is the question below:
2. But Money Doesnt Grow on Trees (45 points)
The company had a good year, and so we want to give out some raises. We generally think that a good raise is 5% of a persons salary. However, we dont have an unlimited amount of money. There are only $25,000 dollars available in our raise budget, and that isnt enough to give everybody a 5% raise, so we need to make some choices.
Management has decided to give people 5% raises until the money runs out. Since there isnt enough money available for everybody, we need a way to prioritize who gets the raises. Management determines that raises should be prioritized in salary order the employees with the lowest salaries should get raises first. If two people have the same salary, they should be prioritized by their hire date, with employees who were hired first having higher priority.
Write a procedure called AssignRaises that determines who will get raises. Your procedure should take the raise percentage (5% in our example above) and raise budget ($25,000 in our example above) as parameters, so that we can vary them when we need to.
The procedure should use a cursor to list the employees in the priority order described above. (Remember that you can use the ORDER BY clause in SQL to do this.) It will loop through the cursor and give raises to the employees using the RaiseSalary procedure you created in part 1. However, it needs to keep track of the declining budget, and not give more than $25,000 in raises. At a certain point, the remaining budget will have declined to the point that there is not enough money left to give the next person in the priority order a full 5% raise. When that happens, the procedure should stop giving raises at all, even if there is some money left in the raise budget.
For each person who does not get a raise, the procedure should write a message to the HW1Log table in the following form:
Not enough money left to give a raise to employee .
Your procedure should finish by printing out the following report.
Number of employees who received raises:
Number of employees who did not receive raises:
Amount of money left unused in the raise budget:
Again, your procedure should COMMIT its changes at the end, just for the sake of this exercise.
Show the code for your procedure, as well as the code and output from the following exercises:
Drop the MyEmployees table (DROP TABLE MyEmployees) and recreate it using the code from part 1(CREATE TABLE MyEmployees AS SELECT * FROM Employees)
Truncate the HW1Log table (TRUNCATE TABLE HW1Log) to remove prior records.
Run the AssignRaises procedure with a raise percentage of 5 and a raise budget of 25000.
Show all of the data from your HW1Log table (can do this with a standard SQL query) order your results by ascending TStamp value.
Show the employee id and salary of all rows from the MyEmployees table (can do this with a standard SQL query) order your results by employee id.
Drop the MyEmployees table (DROP TABLE MyEmployees) and recreate it using the code from part 1(CREATE TABLE MyEmployees AS SELECT * FROM Employees)
Truncate the HW1Log table (TRUNCATE TABLE HW1Log) to remove prior records.
Run the AssignRaises procedure with a raise percentage of 4 and a raise budget of 26000.
Show all of the data from your HW1Log table (can do this with a standard SQL query) order your results by ascending TStamp value.
Show the employee id and salary of all rows from the MyEmployees table (can do this with a standard SQL query) order your results by employee id.
By the way, this is an example of the kind of work that could be done in straight SQL, but it would require some complex statements. The PL/SQL version would be easier to understand for people who dont do much complex SQL work.
part 1 raise salary: Now, create a stored procedure called RaiseSalary that accepts two parameters an employee id and an integer raise percentage. The procedure will raise the salary of the specified employee by the specified percentage. It will do this by updating the Salary column in MyEmployees. Calling the procedure with an argument of 101 for the employee id and 20 for the raise percentage would raise that employees salary by 20 percent.
Your procedure should include exception handling. It should have a generic error handler which prints out both the SQLERRM and the phrase Encountered while trying to give employee a raise. Of course, instead of , your error message should include the value of the employee id parameter that was passed into the procedure.
Every time your procedure raises the salary of an employee, you should write a message to your HW1Log table in the following form:
Employee was raised by percent.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions