1

我正在为 no_data_found 使用用户定义的异常,但仍然看到带有用户定义的异常ORA-20106的ORA-06512堆栈信息

ORA-20106: Problem in loading Affected Circle data
ORA-06512: at "SRUSER.ADD_AFFECTEDCIRCLE", line 30

如何抑制 ORA-06512 堆栈信息?

这是我的代码

CREATE OR REPLACE FUNCTION get_circleID 
( v_circle_code  vf_circle.circle_code%TYPE)
RETURN vf_circle.circle_id%TYPE
IS
    return_value  vf_circle.circle_id%TYPE; 
BEGIN
    BEGIN
        SELECT circle_id INTO return_value
        FROM vf_circle
        WHERE circle_code = v_circle_code;
   END;
   RETURN return_value;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20102, 'Circle Code is wrong or not available',TRUE);
END get_circleID;
/
4

2 回答 2

2

我发现有人在错误/异常处理中请求更少的信息有点奇怪。我通常会尽可能多地转储堆栈跟踪(越多越好!)。但也许你在有正当理由的环境中工作。

你在寻找类似这个例子的东西吗?

-- exception types and related error codes encapsulated 
-- into an application specific package
create or replace package expkg is
  dummy_not_found constant number := -20102;
  dummy_not_found_ex exception;
  -- numeric literal required
  pragma exception_init (dummy_not_found_ex, -20102);
  -- helper to hide a bit esoteric string handling
  -- call only in exception handler !
  function get_exception_text return varchar2;
end;
/

create or replace package body expkg is
  function get_exception_text return varchar2 is
  begin
    -- returns only the first line of a multiline string
    return regexp_substr(sqlerrm, '^.+$', 1, 1, 'm');
  end;
end;
/

begin
  declare
    v_dummy dual.dummy%type;
  begin
    select dummy into v_dummy from dual where dummy = 'A';
  exception
    -- convert exception type
    when no_data_found then
      raise_application_error(expkg.dummy_not_found, 'Not A dummy !', true);
  end;
exception
  when expkg.dummy_not_found_ex then
    -- DIY if the default format doesn't fit 
    dbms_output.put_line(expkg.get_exception_text);
end;
/

输出:

ORA-20102: Not A dummy !
于 2013-08-05T19:08:15.000 回答
1

我认为您需要定义 Pragma 异常 init 来定义用户定义的消息和错误号。如下所示

    pragma exception_init( Message, Number );
于 2013-08-05T17:34:51.983 回答