关于Oracle的独立事物使用方法


在数据清洗时为了方便查看当前运行的状态,特意在存储过程里面添加了一些日志。通过查看日志可以方便的看到当前运行到哪里,但是这输出的日志不能跟过程使用相当的事物(即不管清洗过程是成功还是失败,日志必须得成功写到数据库里面)。Oracle的独立事物就能帮助我们解决这个问题。

  下面是方法模型:

  procedure AddError(i_runid number, --运行号码

  i_append varchar2, --附加信息

  i_type   number default 10 --错误等级0-9错误,10-99警告

  ) is

  pragma autonomous_transaction;

  begin

  insert into dw_log_error

  (log_id, log_runid, log_type, log_append)

  values

  (seq_dw_log_errorid.nextval,

  i_runid,

  i_type,

  substr(i_append, 1, 2000));

  commit;

  end;

  只需要在过程内容调整该过程即可!问题立马解决


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3