oracle ORA-20001、ORA-06512:在第 59 行 ORA-06512 异常错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35398882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:09:50  来源:igfitidea点击:

ORA-20001, ORA-06512: at line 59 ORA-06512 exception error

oracleexceptionplsql

提问by smart_cookie

Here is part of my PL/SQL block where I define an exception. It runs okay when my data does not contain any exceptions but generate the error message when there are exceptions. The error message is as follows:"ORA-20001: Invalid score change. ORA-06512: at line 59 ORA-06512: at line 73"

这是我定义异常的 PL/SQL 块的一部分。当我的数据不包含任何异常时,它运行正常,但在出现异常时生成错误消息。错误信息如下:“ORA-20001: Invalid score change. ORA-06512: at line 59 ORA-06512: at line 73”

I am wondering what went wrong with it. Can anyone help me out here? Thanks.

我想知道它出了什么问题。有人可以帮我从这里出去吗?谢谢。

begin

   if (newpoints<0 or newpoints>maximumpoints) then 
            raise invalid_score_change;
         end if; 
exception 
      when invalid_score_change then
         raise_application_error(-20001,'Invalid score change.');
end;

回答by Rob Mascaro

Even though as others have suggested, the program is doing exactly as you have told it to - your problem is that you have an unbound exception which is causing the outer ORA-06512 which you want to remove. Your problem is that you have raised and exception without a handler for it. If you do not want to see the ORA-06512 message you need to handle the exception like this by wrapper another exception handler around it - BTW this in my opinion is not good practice but I'm just answering your question.

尽管正如其他人所建议的那样,该程序完全按照您的要求执行 - 您的问题是您有一个未绑定的异常,它导致您想要删除的外部 ORA-06512。您的问题是您在没有处理程序的情况下引发了异常。如果您不想看到 ORA-06512 消息,您需要通过在它周围包装另一个异常处理程序来处理这样的异常 - 顺便说一句,我认为这不是一个好习惯,但我只是在回答您的问题。

begin
    begin

       if (newpoints<0 or newpoints>maximumpoints) then 
            raise invalid_score_change;
       end if; 
     exception 
       when invalid_score_change then
       raise_application_error(-20001,'Invalid score change.');
       --- you are now throwing and unhandled exception to be caught by the next handler below
    end;
 exception
     when others then
       ----- do something
     null; -- just to get it to compile
 end;