PL / SQL在函数中的用户定义异常中获取错误

时间:2017-11-16 22:23:15

标签: oracle plsql

在我的PL / SQL程序中,我创建了三个例外:divide_by_zeroothers和一个用户定义的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:

enter image description here

0 个答案:

没有答案