从Delphi执行Oracle的存储过程如何捕捉Oracle存储过程中的错误信息?
如果能举出一个小例子最好了.
下面是我的执行存储过程的程序段:(我的存储过程有两个参数,执行insert操作)
with sp_CH do
  begin
    Close;
    StoredProcName:='SP_CH';
    Params.Clear;
    Params.CreateParam(ftInteger,'N_lsh',ptInput);
    Params.CreateParam(ftString,'N_DZR',ptInput);    //添加结算人   
    ParamByName('N_lsh').AsInteger:=rkdlsh;
    ParamByName('N_DZR').AsString:=f_main.gs_loginname;  
    ExecProc  ;
  end;

解决方案 »

  1.   

    我使用TStoredPro控件执行存储过程
      

  2.   

    最好在存储过程中 用try,catch来检测错误,然后将错误消息格式化发给客户端
      

  3.   

    try
      ...
    except
      ...
    end.
      

  4.   

    declare 
      ....
    begin  
      .....
    exception
      when .... thenend ;
      

  5.   

    能否有个简单的例子?
    DELPHI应用程序接受到错误信息.
      

  6.   

    给个例子,我在SQL Server 2000+Delphi7下可以抛出错误的例子,应该是通用的,说明部分略:
    -----------------------------------------------------------------
    --****************************
    --参数:*****************************************
    --说明:***************************************
    --返回:*********************************************
    --表:
    --算法:
    --建立:chenyansong 2003-8-21 16:03
    -----------------------------------------------------------------
    if exists (select * from sysobjects where id = object_id('dbo.TL_GetTablesName') and sysstat & 0xf = 4)
        drop procedure dbo.TL_GetTablesName
    GO
    create procedure dbo.TL_GetTablesName @begindate datetime,@enddate datetime,
        @tablename char(64),@tables char(1024) output
    WITH ENCRYPTION
    -----------------------------------------------------------------
    --Version Number:Apple1.0_20030821_01,Last Mender:chenyansong
    -----------------------------------------------------------------
    AS BEGIN
      declare @Err int;
      declare @BreakPoint int;
      declare @Msg varchar(255);  declare @strTableName char(32);
      declare @str1 char(4);
      declare @str2 char(2);  select @tables=ltrim(rtrim(@tablename));
      select @str1=Year(@begindate);
      select @str2=Month(@begindate);
      if len(@str2)=1 select @str2='0'+@str2;
      select @strTableName=ltrim(rtrim(@tablename))+@str1+@str2;
      if exists (select * from dbo.sysobjects where name=@strTableName)
        select @tables=ltrim(rtrim(@tables))+','+ltrim(rtrim(@strtablename));
      while not ((Year(@begindate)=Year(@enddate)) and (Month(@begindate)=Month(@enddate))) begin
        select @begindate=dateadd(mm,1,@begindate);
        select @str1=Year(@begindate);
        select @str2=Month(@begindate);
        if len(@str2)=1 select @str2='0'+@str2;
        select @strTableName=ltrim(rtrim(@tablename))+@str1+@str2;
        if exists (select * from dbo.sysobjects where name=@strTableName)
          select @tables=ltrim(rtrim(@tables)) +',' +ltrim(rtrim(@strtablename));
      end;
      select @Err=@@Error,@Msg='取表名时出错!',@BreakPoint=359550;
      if (@Err is null) or (@Err!=0)  goto ErrHandle;
      return 0;
      ErrHandle:
      raiserror('%s,断点=%d,Err=%d',16,1,@Msg,@BreakPoint,@Err);
      return -1;
    End
    Go
      

  7.   

    在ORACLE的存储过程的接口中定义一个字符串变量用来返回在ORACLE中的错误信息就可以了哈。在ORACLE的存储过程中也可以用BEGINEXCEPTIONEND这样的语句段来获取异常,然后把异常传给DELPHI就可以了。光用DELPHI的TRYEXCEPTEND是没有办法获取后台中的错误的。