I have a table employee with columns: id, name, department, salary. I want to create a procedure which increase salary for all employees in a specific department and run procedure if salary is less than 500, otherwise return to savepoint. I don't know how to write the exception
CREATE PROCEDURE `procedure1` (IN dep1 INT(11), IN sal1 INT(11))
BEGIN
SAVEPOINT point1;
UPDATE employee SET salary=salary+sal1
WHERE department=dep1;
EXCEPTION
WHEN salary>500 THEN
ROLLBACK TO point1;
END
maybe you need to review your point of view, because you can add another WHERE clause in order to update only those salaries who are less than or equal to 500, eg:
UPDATE employee SET salary=salary+sal1
WHERE department=dep1
AND salary <= 500;
With this I think you don't need a SAVEPOINT, however find here how to use it: SAVEPOINT
Hope this help!!.
CREATE OR REPLACE PROCEDURE procedure1 (dep1 IN NUMBER, sal1 IN NUMBER)
BEGIN
UPDATE employee SET salary=salary+sal1
WHERE department= dep1 and
salary <= 500;
COMMIT;
END;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.