Autonomous Transaction 即事务中的事务,它可以独立父事务进行提交或回滚;下面进行一个例子来看它是体现;
自治事务autonomous transaction
1.create table t
create table t(msg varchar2(25));
2.autonomous_insert procedure
create or replace procedure Autonomous_Insert
as
pragma autonomous_transaction;
begin
insert into t values('Autonomous Insert');
commit;
end;
/
3.create nonAutonomous Insert procedure
create or replace procedure nonAutonomous_Insert
as
begin
insert into t values('nonAutomous Insert');
commit;
end;
/
Procedure created
下面来观察PL/SQL代码匿名块非自治事务行为
begin
insert into t values ('Anonymous Block');
nonAutonomous_Insert;
rollback;
end;
/
SQL> select * from t;
MSG
-------------------------
Anonymous Block
nonAutomous Insert
删除t表中的数据
delete from t;
commit;
下面来观察PL/SQL代码匿名块自治事务行为
begin
insert into t values ('Anonymous Block');
Autonomous_Insert;
rollback;
end;
/
SQL> select * from t;
MSG
-------------------------
Autonomous Insert