Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PL / SQL homewerk help needed. I ' m using SQL developer. Please use PL / SQL and use SQL Developer Here is the questions

PL/SQL homewerk help needed. I'm using SQL developer. Please use PL/SQL and use SQL Developer
Here is the questions below:
1. The Raise Procedure (40 points
Create a copy of the EMPLOYEES table by running the following code:
CREATE TABLE MyEmployees AS SELECT * FROM HR.Employees;
Now, create a new table that you will use for logging.
CREATE TABLE HW1Log
(
Message VARCHAR2(200),
TStamp TIMESTAMP DEFAULT SYSTIMESTAMP
);
Notice that the TStamp column was created with a default value. You can add a log message to the table like this:
INSERT INTO HW1Log (Message) VALUES ('Some message');
If you look at the table now, youll see that the timestamp column has been populated automatically. Later on, youll be asked to use code like this to write messages to your log table.
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.
Note that an UPDATE statement that affects zero records wont cause an exception. Implicit cursor attributes can help you determine if anybodys salary was actually raised.
Do a COMMIT; inside your procedure (after all the other code in the BEGIN section but before EXCEPTION) to make your changes public and permanent. Its not always a good idea to have a COMMIT inside your procedures, but for the sake of this exercise, please put one in there.
Show the code for your procedure, as well as the code and output from the following exercises:
Show the initial salary of employee 179(can do this with a standard SQL query)
Call your procedure with an employee id of 179 and a percentage of 10
Show the salary of employee 179 after the procedure call (can do this with a standard SQL query)
Show the initial salary of employee 202(can do this with a standard SQL query)
Call your procedure with an employee id of 202 and a percentage of 15
Show the salary of employee 202 after the procedure call (can do this with a standard SQL query)
Call your procedure with an employee id of 500 and a percentage of 20
Show all of the data from your HW1Log table (can do this with a standard SQL query) order your results by ascending TStamp value.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions