首页 > 开发 > 综合 > 正文

用一个示例讲解自治事务和非自治事务的区别

2024-07-21 02:44:15
字体:
来源:转载
供稿:网友

下面是个简单的测试,可以让大家更加清楚的明白自治事务和非自治事务的区别:


SQL> create table chris_test (name varchar2(200));


Table created.


SQL> create or replace PRocedure Autonomous_insert

2 as

3 pragma autonomous_transaction;

4 begin

5 insert into chris_test values ('Autonomous Insert!');

6 commit;

7 end;

8 /


Procedure created.


SQL> create or replace procedure Nonnomous_insert

2 as

3 begin

4 insert into chris_test values ('Nonnomous Insert!');

5 commit;

6 end;

7 /


Procedure created.


SQL> begin

2 insert into chris_test values ('Anonymous Block!');

3 Nonnomous_insert;

4 rollback;

5 end;

6 /


PL/SQL procedure successfully completed.


SQL> select * from chris_test;


NAME

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

Anonymous Block!

Nonnomous Insert!


SQL> truncate table chris_test;


Table truncated.


SQL> begin

2 insert into chris_test values ('Anonymous Block!');

3 Autonomous_insert;

4 rollback;

5 end;

6 /


PL/SQL procedure successfully completed.


SQL> select * from chris_test;


NAME

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

Autonomous Insert!


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表