plsql事务处理(二)

自治事务

看看在oracle中一个事务调用另外一个事务的情况:

事务A

Begin

    DML;

    事务B

End;

事务B

Begin

    Commit;

End;

事务A对事务B中的操作可见,如果在事务Bcommit,会将事务A中的DMLcommit掉,自治事务就是来解决这样的问题的,使得事务B中的提交或回滚对A不可见。

使用一个例子来对比一下自治事务和普通的事务的不同:

SQL> create or replace procedure pro_test_tran is

 2 begin

 3  commit;

 4 end;

 5 /

 

Procedure created

 

使用pragma autonomous_transaction;来标识使用自治事务

SQL>

SQL> create or replace procedure pro_test_auto is

 2   pragma autonomous_transaction;

 3 begin

 4   commit;

 5 end;

 6 /

 

Procedure created

 

SQL> select a.sal from scott.emp a where a.empno = 7369;

 

        SAL

------------

     812.60

 

SQL> begin

  2   update scott.emp a set a.sal = a.sal + .01 where a.empno = 7369;

 3   pro_test_auto;

 4   rollback;

 5 end;

 6 /

 

PL/SQL procedure successfully completed

 

调用了pro_test_auto以后并没有将父事务中的dml提交掉:

SQL> select a.sal from scott.emp a where a.empno = 7369;

 

        SAL

------------

     812.60

 

SQL>

 

SQL> begin

 2   update scott.emp a set a.sal = a.sal + .01 where a.empno = 7369;

 3   pro_test_tran;

 4   rollback;

 5 end;

 6 /

 

PL/SQL procedure successfully completed

 

调用了pro_test_ tran将父事务中的dml提交掉了:

 

SQL> select a.sal from scott.emp a where a.empno = 7369;

 

        SAL

------------

     812.61

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值