Skip to content
Advertisement

PL/SQL CREATE PROCEDURE – Salary increase based on tenure

I have worked on this for a while but the code did not work and I could not figure out the correct solution. Did I miss something from the code? Thank you.

— Question – The company wants to calculate the employees’ annual salary: –The first year of employment, the amount of salary is the base salary which is $10,000. –Every year after that, the salary increases by 5%. –Write a stored procedure named calculate_salary which gets an employee ID and –for that employee calculates the salary based on the number of years the employee has –been working in the company. (Use a loop construct to calculate the salary). –The procedure calculates and prints the salary. –Sample output: –First Name: first_name –Last Name: last_name –Salary: $9999,99 –If the employee does not exists, the procedure displays a proper message.

Advertisement

Answer

The calculation in the FOR loop is wrong. In the first loop iteration you are setting SALARY to zero. In the second iteration, you are setting SALARY equal to base_salary. In the third iteration you are setting SALARY to double base_salary, etc. Also, in PL/SQL, FOR loop limits are inclusive. Hence your loop should start at 1 (one) and not 0 (zero).

The below code calculates the salary assuming that the increase is based on the current salary and not the base salary. Changes to your code are indicated by comments at the end of the changed line.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement