在我的PL / SQL程序中,我创建了三个例外:divide_by_zero
,others
和一个用户定义的divide_by_one
,但我的用户定义的异常不起作用。我创建了一个块语句来处理每个异常但我收到的错误如屏幕截图所示。任何人都可以帮我确定问题吗?
码
CREATE OR REPLACE
PACKAGE CALCULATOR AS
FUNCTION DivNumber(divend IN Number, divend2 IN Number) RETURN NUMBER;
END CALCULATOR;
/
CREATE OR REPLACE
PACKAGE BODY CALCULATOR AS
FUNCTION DivNumber(divend IN Number, divend2 IN Number) RETURN NUMBER AS
e_ZERO_DIVIDE EXCEPTION;
BEGIN
-- the condition
IF divend2 = 0 THEN
Raise e_ZERO_DIVIDE;
ELSIF divend2 = 1 THEN
Raise one_divide;
END IF;
return divend / divend2;
--Exception handling
EXCEPTION
WHEN e_ZERO_DIVIDE THEN
dbms_output.put_line('Division by 0 or null');
RETURN 1;
WHEN one_divide THEN
dbms_output.put_line('Division by 1 or null');
RETURN NULL;
WHEN OTHERS THEN
dbms_output.put_line('ERROR: '||sqlerrm);
RETURN 1;
END DivNumber;
END CALCULATOR;
/
select calculator.DivNumber(12,1) from dual;
outout: