In this exercise you will add an error handler to the stored procedure created in exercise 2.
Tasks:
Declare an error handler for the first stored procedure below. The error handler should follow these specs:
- handler_action: EXIT
- condition_name: NOT FOUND
- or condition_name: SQLWARNING
- or condition_name: SQLEXCEPTION
delimiter $$
DROP PROCEDURE IF EXISTS sp_ModifyName$$
CREATE PROCEDURE sp_ModifyName (IN currentName VARCHAR(40), IN newName VARCHAR(40))
BEGIN
DECLARE cID VARCHAR(5);
SET cID = (SELECT CustomerID from customers where CompanyName = currentName);
UPDATE customers SET CompanyName = newName WHERE CustomerID = cID;
END$$
delimiter ;
This reference is very useful.
Solution