Create-a-PLSQL-Function-to-calculate-increment-for-the-employees - cover image

Create 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.

Table: EMPLOYEE

COLUMN DATATYPE CONS.
EMPID NUMBER(5) PK
EMPNAME VARCHAR2(25) NOT NULL
SALARY NUMBER(10,2)

Functional Requirement: FUNCTION calculate_Increment(incperc number, salary number)

(Hint: Data is case sensitive. Use '/' to terminate the PLSQL block)

Here’s a simple, step-by-step procedure for creating a PL/SQL function to calculate employee increments:

Start with the Function Declaration: Begin by using the CREATE OR REPLACE FUNCTION statement to name your function, calculate_Increment. Specify two parameters: incperc (increment percentage) and salary (current salary), both as numbers.

Define the Return Type: Indicate that your function will return a number using the RETURN number clause.

Begin the Function Body: Use the IS keyword to start the function body.

Implement the Logic: Inside the BEGIN and END; keywords, write the logic to calculate the increment. Multiply the salary by the increment percentage divided by 100.

Return the Result: Use the RETURN statement to output the calculated increment.

By following the steps above, you have successfully created a PL/SQL function, calculate_Increment, which calculates the increment for an employee's salary based on a given percentage. This function takes two parameters, the increment percentage and the salary, and returns the calculated increment. This efficient and reusable function can be integrated into larger PL/SQL programs to manage salary adjustments with ease.

Leave a comment