ORACLE存储过程异常处理。

create or replace procedure p_tx_getfaxdata
(   
)
as
v_ErrorCode NUMBER;          -- 出错的代码
v_ErrorMsg  VARCHAR2(200);   -- 错误的消息显示
v_CurrentUser VARCHAR2(8);   -- 当前数据库用户
v_Information VARCHAR2(100); -- 关于错误的信息

begin

  //do the things you need to do.

    commit;

    --异常捕捉
    Exception
        when others then
        begin
            v_ErrorCode := SQLCODE;
            v_ErrorMsg := SQLERRM;
            v_CurrentUser := USER;
            v_Information := '遇到了错误 ' || TO_CHAR(SYSDATE) || ' 数据库用户 ' || v_CurrentUser;
            dbms_output.put_line('执行错误,自动回滚');
            dbms_output.put_line('详细信息:'||'错误代码:'||v_ErrorCode||',错误消息:'||v_ErrorMsg||',日志信息:'||v_Information);

             rollback;
        end;
end p_tx_getfaxdata;

posted @ 2011-03-24 13:36  傲衣华少  阅读(362)  评论(0编辑  收藏  举报