【问题标题】:Get Actual Error Message From Oracle Exception In Dot Net从 Dot Net 中的 Oracle 异常获取实际错误消息
【发布时间】:2012-05-08 19:58:04
【问题描述】:

我有这个程序:

create or replace PROCEDURE MyProc
(
     <some-parameters>
)
AS
  BEGIN
    if(<some-condition>) then
        RAISE_APPLICATION_ERROR('my custom error message');
    end if;
  END;

当从 C# 调用它时:

try
{
    <call procedure>
}
catch(OracleException x)
{
    lblMessage.Text = x.Message;
}

我收到如下错误消息:

ORA-28008: my custom error message ORA-06512: at blah, line blah ORA-06512: at line blah

我只想要:

my custom error message

没有内部异常。错误收集没有帮助。使用 Exception 而不是 OracleException 时的情况相同。

我错过了什么?

我可以使用字符串操作,但错误消息的格式有多固定?

【问题讨论】:

  • 自定义错误消息的 ORA-xxxxx 编号是否对于每条错误消息都是唯一的?

标签: oracle stored-procedures


【解决方案1】:

我使用返回参数来捕获 php。我认为相同的技术将在.net 中有用。 (我认为可以在异常处理中捕获自定义消息并仅重新引发该自定义消息,但下面的方法肯定有效。:)

create or replace PROCEDURE MyProc (p_result out varchar2)
is
  ...
begin
  ...
  if error then
    p_result := 'my custom error message';
    return; -- exit procedure 
  end if;

  p_result := 'ok';
end;

【讨论】:

    【解决方案2】:

    试试

    PKG_MSG.RAISE_ERROR(0,null,'我的自定义错误信息',null,null,null,null,null,null,null,null,null,null );

    而不是

    RAISE_APPLICATION_ERROR('我的自定义错误信息');

    【讨论】:

    • 什么是pkg_msg?看起来像一个自定义库/包。
    猜你喜欢
    • 2014-08-11
    • 2011-05-26
    • 2017-02-11
    • 2012-10-08
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 2017-04-20
    • 1970-01-01
    相关资源
    最近更新 更多