Knowee
Questions
Features
Study Tools

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

Question

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

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide on how to create a PL/pgSQL block that defines a procedure named update_employee_salary:

  1. Open your PostgreSQL database interface.

  2. Start by defining the procedure. In PostgreSQL, you use the CREATE OR REPLACE PROCEDURE statement to create a new procedure or replace an existing one.

  3. Specify the name of the procedure, which in this case is update_employee_salary.

  4. Define the parameters that the procedure will take. In this case, it's employee_id and new_salary.

  5. Use the LANGUAGE clause to specify the language name that the procedure is implemented in. In this case, it's plpgsql.

  6. Use the AS clause to provide the code block that implements the procedure. In this case, it's an UPDATE statement that updates the salary column of the employee table for the row that has the eid equal to the employee_id parameter.

Here is the SQL code that implements the above steps:

CREATE OR REPLACE PROCEDURE update_employee_salary(employee_id INT, new_salary NUMERIC)
LANGUAGE plpgsql
AS $$
BEGIN
   UPDATE employee
   SET salary = new_salary
   WHERE eid = employee_id;
END;
$$;

To call this procedure, you would use the CALL statement like this:

CALL update_employee_salary(1, 50000);

This would update the salary of the employee with eid of 1 to 50000.

This problem has been solved

Similar Questions

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

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

For the Employee Class Program in this tutorial, what if we need the capability to update the salary for employees? What information is needed to perform this task, and what code segment implements obtaining it in a method?a.)Employees file information and the new salarydef upd_salary(): employees = read_employees() new_sal = input("Enter the new salary of the employee: ")b.)The new salarydef upd_salary(employees): new_sal = input("Enter the new salary of the employee: ")c.)Employee iddef upd_salary(employees): empid = input("Enter the employee ID: ")d.)Employee id and the new salarydef upd_salary(employees): empid = input("Enter the employee ID: ") new_sal = input("Enter the new salary of the employee: ")

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

Given a table salary, such as the one below, that has m=male and f=femalevalues. Swap all f and m values (i.e., change all f values to m and vice versa)with a single update statement and no intermediate temp table.Note : You must write a single update statement, DO NOT write any selectstatement for this problem.Example:idnamesexsalary1Am25002Bf15003Cm55004Df500After running your update statement, the above salary table should have thefollowing rows:idnamesexsalary1Af25002Bm15003Cf55004Dm500Optionsupdate salaryset sex = if(sex = 'm', 'f', 'm');update salaryset sex = if(sex = 'm', 'm', 'm');update nameset salary = if(name = 'm', 'f', 'm');update salaryset sex = if(sex != 'f', 'm', 'm');

1/2

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.