SQL> truncate table tt7;
表被截断。
SQL> create or replace procedure proc_autotrans
2 is
3 pragma autonomous_transaction;
4 begin
5 insert into tt7 values(1,'autonomous');
6 commit;
7 end;
8 /
过程已创建。
SQL> begin
2 insert into tt7 values(1,'niminblock');
3 proc_autotrans;
4 rollback;
5 end;
6 /
PL/SQL 过程已成功完成。
SQL> select * from tt7;
ID NAME
---------- ----------
1 autonomous
--只插入过程中提交的数据,plblock中的数据被rollback了,显然过程中的事务是独立的,否则应该插入2条数据,因为procedure中有commit
SQL> edit
已写入 file afiedt.buf
1 create or replace procedure proc_nonautotrans
2 is
3 --pragma autonomous_transaction;
4 begin
5 insert into tt7 values(1,'autonomous');
6 commit;
7* end;
SQL> /
过程已创建。
SQL> truncate table tt7;
表被截断。
SQL> edit
已写入 file afiedt.buf
1 begin
2 insert into tt7 values(1,'niminblock');
3 proc_nonautotrans;
4 rollback;
5* end;
SQL> /
PL/SQL 过程已成功完成。
SQL> select * from tt7;
ID NAME
---------- ----------
1 niminblock
1 autonomous
SQL>
--rollback没有什么可回滚的了,因为外面的事务被procedure中的commit提交了
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/19602/viewspace-1015348/ ,如需转载,请注明出处,否则将追究法律责任。