Create table Msg (Msg varchar(50)) ;
自制事务:
create or replace procedure AutoNomouse_Insert is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
insert into Msg values('AutoNomouse Insert');
commit;
end;
非自治事务:
CREATE OR REPLACE Procedure NonAutoNomouse_Insert as
begin
insert into Msg Values('NonAutonomouse Insert');
commit;
end;
SQL> begin
2
3 insert into Msg Values('This Main Info');
4
5 NonAutoNomouse_Insert;
6
7 rollback;
8
9 end
10 ;
11 /
PL/SQL procedure successfully completed
SQL> select * from msg;
MSG
--------------------------------------------------
This Main Info
NonAutonomouse Insert
因为过程中有COMMIT;所以匿名块中得RULLBACK 是不起作用的; 由此得出:非自治事务中的COMMIT,ROLLBACK
是会影响整个事务的。
下面我们看一个另外一种情况:
SQL> delete msg;
2 rows deleted
SQL>
这里没有COMMIT;
SQL> begin
2
3 insert into Msg Values('This Main Info');
4
5 rollback; --这里加了ROLLBACK;
6
7 NonAutoNomouse_Insert;
8
9 rollback;
10
11 end
12 ;
13 /
PL/SQL procedure successfully completed
SQL> select * from msg;
MSG
--------------------------------------------------
This Main Info
NonAutonomouse Insert
NonAutonomouse Insert
竟然没有ROLLBACK (DELETE * FROM MSG ;) 为什么? 因为过程就是一个新的SESSION,所以前面的SESSION
被正常EXIT,同时被自动提交; 所以我们会看到三行数据。