例11(ゼロ除算エラーの回避)
この例は、「ゼロ除算」エラーを防ぎます。
PROCEDURE divide
(IN dividend INT, IN divisor INT, OUT result INT, OUT message CHAR)
BEGIN
DECLARE divide_by_zero EXCEPTION;
IF divisor = 0 THEN
RAISE divide_by_zero value 'Divided by zero error';
END IF;
SET result = dividend/divisor;
EXCEPTION
WHEN divide_by_zero THEN
SET message = CURRENT_EXCEPTION.MESSAGE;
END