Create PL/pgSQL procedure for the increment of employees where in salary less than 35000 will get hike of 15% in their previoussalary and other will get 10% hike in their previous salary. Using following schema, Employees (id, name, department, salary)call the procedure by id and print employee’s name with their updated salary
Question
Create PL/pgSQL procedure for the increment of employees where in salary less than 35000 will get hike of 15% in their previoussalary and other will get 10% hike in their previous salary. Using following schema, Employees (id, name, department, salary)call the procedure by id and print employee’s name with their updated salary
Solution
Here is a step-by-step guide to creating a PL/pgSQL procedure for incrementing employee salaries based on the conditions you provided:
Step 1: Define the procedure.
CREATE OR REPLACE PROCEDURE update_salary(emp_id INT)
LANGUAGE plpgsql
AS $$
Step 2: Declare the variables you will use.
DECLARE
emp_name VARCHAR;
emp_salary INT;
Step 3: Begin the procedure body.
BEGIN
Step 4: Retrieve the name and salary of the employee with the given ID.
SELECT name, salary INTO emp_name, emp_salary
FROM Employees
WHERE id = emp_id;
Step 5: Check if the employee's salary is less than 35000. If it is, increase it by 15%. Otherwise, increase it by 10%.
IF emp_salary < 35000 THEN
emp_salary := emp_salary * 1.15;
ELSE
emp_salary := emp_salary * 1.10;
END IF;
Step 6: Update the employee's salary in the database.
UPDATE Employees
SET salary = emp_salary
WHERE id = emp_id;
Step 7: Print the employee's name and their updated salary.
RAISE NOTICE 'Employee % has a new salary of %', emp_name, emp_salary;
Step 8: End the procedure body and the procedure definition.
END;
$$;
Step 9: Call the procedure with an employee ID.
CALL update_salary(1);
This will print a message with the employee's name and their new salary.
Similar Questions
In PostgreSQL, create a PL/pgSQL block that defines a procedure namedupdate_employee_salary which takes two parameters: employee_id and new_salary. This procedure should update the salary ofthe employee with the given employee_id to the new salary value. Assume “employee” table with fields – eid, ename and salary
A) Write PL/pgSQL function to increment the employee’s salary by 10% if his/her department is ‘HR’ for given(inputted)employee_id.Schema: Employee(employee_id, first_name, last_name, department, salary)B) Write PL/pgSQL function to find the number of Sundays between given dates
In PostgreSQL, create a PL/pgSQL block that defines a function named calculate_salary_bonus which takes two parameters:employee_id and bonus_percentage. This function should calculate the bonus amount for the employee with the givenemployee_id based on their current salary and the provided bonus percentage. Assume “employee” table with fields – eid, enameand salary
Which of the below queries displays employees' name and new salary after the increment of 1000
payraiseProblem DescriptionA company has N employees, numbered 0 to N-1. The boss of the company is employee 0, while every other employee i has a direct superior Pi. Since employee 0 has no direct superior, P0 = -1. Each employee i starts with an initial salary of Si dollars.There will be a total of Q operations that you have to handle, each of them being one of two types:A raise operation, where we raise the salaries of employee x and all of their direct and indirect subordinates by d dollars.A query operation, where we want to know the current salary of employee x.InputThe first line of input will contain two integers, N and Q.The next line of input will contain N integers, indicating the array P.The next line of input will contain N integers, indicating the array S.The next Q lines of input will describe one operation each, in the following formats:0 x d, indicating a raise operation on employee x (and their subordinates) by d dollars.1 x, indicating a query operation on employee x.OutputThe output should contain one line with one integer for each query operation, indicating the current salary of the requested employee.Limits1 ≤ N, Q ≤ 106.0 ≤ Pi < i, for all 1 ≤ i < N.0 ≤ x < N0 ≤ d, Si ≤ 109.Sample Input5 5-1 0 0 1 11 3 2 3 20 1 31 40 0 21 11 3Sample Output588
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.