Answered step by step
Verified Expert Solution
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
PLSQL help needed. Im using SQL developer. Here is the question below:
But Money Doesnt Grow on Trees points
The company had a good year, and so we want to give out some raises. We generally think that a good raise is of a persons salary. However, we dont have an unlimited amount of money. There are only $ dollars available in our raise budget, and that isnt enough to give everybody a raise, so we need to make some choices.
Management has decided to give people 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 in our example above and raise budget $ 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 However, it needs to keep track of the declining budget, and not give more than $ 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 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 HWLog 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 CREATE TABLE MyEmployees AS SELECT FROM Employees
Truncate the HWLog table TRUNCATE TABLE HWLog to remove prior records.
Run the AssignRaises procedure with a raise percentage of and a raise budget of
Show all of the data from your HWLog 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 CREATE TABLE MyEmployees AS SELECT FROM Employees
Truncate the HWLog table TRUNCATE TABLE HWLog to remove prior records.
Run the AssignRaises procedure with a raise percentage of and a raise budget of
Show all of the data from your HWLog 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 PLSQL version would be easier to understand for people who dont do much complex SQL work.
part 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 for the employee id and for the raise percentage would raise that employees salary by 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 HWLog table in the following form:
Employee was raised by percent.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started