Create a PL/SQL Function to calculate increment for the employees.
You can achieve this using simple SQL update statment.
Let us consider a table called employee. Here I got four rows.
IDE Name_NM Salary_SA
1 Nayani 1000
2 Kapil 1000
3 Sundhar 10000
4 Devis 20000
I want to increase the salary of employee by 10 percent. For this I can wrire a query as below
UPDATE Employee SET Salary= (Select Salary+ (Select Salary*0.1))
This will increase all employee salary by 10 percent.
IDE Name_NM Salary_SA
1 Nayani 1100
2 Kapil 1100
3 Sundhar 11000
4 Devis 22000
For suppose I want to increase a particular employee salary by 20 percent I can write a query as
UPDATE Employee SET Salary= (Select Salary+ (Select Salary*0.1)) Where ID = 2
Hey try this function it worked for me.
SQL> create or replace function calculate_emp_salary_increment
2 (incpercent in number,
3 salary in number
4 )
5 return number
6 as
7 begin
8 return salary * incpercent/100;
9 end;
10 /
Function created.
SQL> select emp_id, emp_name, salary, calculate_emp_salary_increment(20, salary) INCREMENT
2 from employee;
EMP_ID EMP_NAME SALARY INCREMENT
---------- ---------- ---------- ----------
1234 MIKE 2450 245
1235 Peter 5000 500
1236 JOHN 1300 130