Forum

Write a PL/SQL Func...
 
Notifications
Clear all

Write a PL/SQL Function to Calculate Increment for the Employees. Function will take increment percentage and salary as input and return increment amount as output.


Rahul Updhyay
Posts: 17
Topic starter
(@rahul)
Active Member
Joined: 1 year ago

Write a PL/SQL Function to calculate increment for the employees. Function will take increment percentage and salary as input and return increment amount as output.

2 Replies
John
Posts: 15
 John
(@John)
Joined: 1 year ago

You can achieve this using a simple SQL update statement.

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 employees by 10 percent. For this, I can write a query as below

UPDATE Employee SET Salary= (Select Salary+ (Select Salary*0.1))

This will increase all employee salaries 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

 

 

Reply
KV Kumar
Posts: 27
Admin
(@vinodkrsetty)
Member
Joined: 2 years ago

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
Reply
Share: