如何在Oracle PLSQL中提交单个事务 [英] How to commit individual transaction in Oracle PLSQL

查看:788
本文介绍了如何在Oracle PLSQL中提交单个事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个PL/SQL过程,在此过程中,我需要在其自己的事务范围内调用另一个过程,并与主要事务的失败或提交无关地提交它.换句话说,我需要诸如REQUIRES NEW事务传播之类的东西.

I need to write a PL/SQL procedure, within this procedure I need to call another procedure within its own transaction bounds, and commit it regardless of failure or commit of main transaction. In other words I need something like REQUIRES NEW transaction propagation.

类似的东西:

procedure mainProcedure(arugements) is 
begin
    // some statements
    nestedProcedure(someArguments);
    // some other statements
end;

procedure nestedProcedure(arguments) is
begin
  // start a new transaction
  // some statements, lock some objects!
  // commit the new transaction and release locked objects
end;

我该如何实现?

推荐答案

您可以使用pragma autonomous_transaction.它可以满足您的需求.但是请不要忘记,在子事务中您将看不到上述事务的任何更新.

You may use pragma autonomous_transaction. It does the same what you need. But don't forget that in the sub transaction you will not see any updates from above transactions.

procedure mainProcedure(arugements) is 
begin
    // some statements
    nestedProcedure(someArguments);
    // some other statements
end;

procedure nestedProcedure(arguments) is
pragma autonomous_transaction;
begin
  // start a new transaction
  // some statements, lock some objects!
  // commit the new transaction and release locked objects
  commit; 
end;

这篇关于如何在Oracle PLSQL中提交单个事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆