| 導購 | 订阅 | 在线投稿
分享
 
 
 

用一個示例講解自治事務和非自治事務的區別

來源:互聯網網民  2008-07-26 07:41:59  評論

下面是個簡單的測試,可以讓大家更加清楚的明白自治事務和非自治事務的區別:

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!

 
特别声明:以上内容(如有图片或视频亦包括在内)为网络用户发布,本站仅提供信息存储服务。
 
下面是個簡單的測試,可以讓大家更加清楚的明白自治事務和非自治事務的區別: 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!
󰈣󰈤
王朝萬家燈火計劃
期待原創作者加盟
 
 
 
>>返回首頁<<
 
 
 
 
 
 熱帖排行
 
 
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有