ITPub博客

首页 > IT职业 > IT生活 > 自治事务!

自治事务!

原创 IT生活 作者:warehouse 时间:2008-12-27 18:50:51 0 删除 编辑
自治事务允许我们在"事务中创建事务"[@more@]

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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 事务的原子性!
下一篇: CX0的全称!
请登录后发表评论 登录
全部评论

注册时间:2007-12-07

  • 博文量
    717
  • 访问量
    5366330