写了个两个数除法的功能,但是exception的条件是除数不能为零的时候老是报错,不知道怎么写,求教!
CREATE OR REPLACE FUNCTION
devision(dividend IN NUMBER,divisor IN NUMBER)
RETURN NUMBER IS
re NUMBER;
BEGIN
re := dividend/divisor;
RETURN re;
EXCEPTION
WHEN divisor = 0 THEN
DBMS_OUTPUT.PUT_LINE('ERROR!');
END;
/
show error
--begin
--dbms_output.put_line(to_char(devision(4,2)));
--end;
------解决方案--------------------
CREATE OR REPLACE FUNCTION
devision(dividend IN NUMBER,divisor IN NUMBER)
RETURN NUMBER IS
re NUMBER;
e_divisor_0 exception;
BEGIN
if divisor=0 then
raise e_divisor_0;
end if;
re := dividend/divisor;
RETURN re;
EXCEPTION
WHEN e_divisor_0 THEN
DBMS_OUTPUT.PUT_LINE('ERROR!');
END;
/
exception后面的只能跟异常类型
------解决方案--------------------
WHEN others THEN
DBMS_OUTPUT.PUT_LINE('ERROR!');