博客首页 注册 建议与交流 排行榜 加入友情链接
推荐 投诉 搜索: 帮助

CLEANER

如果你的工作,机器也可以做。那总有一天,你也要变成机器。
   yuechaotian.cublog.cn
关于作者  
name:yuechaotian
employment:coder
age:25
from:NEU
about me:a retardate
email:yuechaotian(at)gmail.com
msn:yuechaotian(at)hotmail.com

我的分类  




SET TRANSACTION READ ONLY
将当前事务设置为只读模式。在该模式下所发出的查询,都是查询的设置事务只读模式时的数据状态(通过一致性读取实现)。比如我在 session 1 中设置事务为只读模式:
 
-- session 1
SQL> set transaction read only;
 
事务处理集。
 
SQL> select * from test1;
 
A                             B
-------------------- ----------
test1                        99
test1                      1010
test1                      1111
test1                      1212
test1                      1313
tianyc                     6666
 
已选择6行。
 
在 session 2 中,我修改 test1 中数据,并提交:
 
-- session 2
SQL> insert into test1 values('new', 9999);
 
已创建 1 行。
 
SQL> commit;
 
提交完成。
 
SQL> select * from test1;
 
A                             B
-------------------- ----------
test1                        99
test1                      1010
test1                      1111
test1                      1212
test1                      1313
tianyc                     6666
new                        9999
 
已选择7行。
 
此时,虽然事务已经持久化到数据库中了,但在 session 1 中查询到的仍是 6 条数据:
 
-- session 1
SQL> set transaction read only;
 
事务处理集。
 
SQL> select * from test1;
 
A                             B
-------------------- ----------
test1                        99
test1                      1010
test1                      1111
test1                      1212
test1                      1313
tianyc                     6666
 
已选择6行。
 
这个功能有什么用处呢?当你要做多个报表时,为了构造一致的数据,避免由于制作报表期间数据被更新而导致不平衡的数据出现,可以设置你的事务为只读模式。

 发表于: 2008-06-08,修改于: 2008-06-08 08:19 已浏览452次,有评论1条 推荐 投诉

  网友评论
  edeed 时间:2008-06-08 11:48:45 IP地址:123.59.64.★
我尝试了一下,在oracle10g中,没有得到你说的结果

Blog作者的回复:
我是用9201做的测试,刚刚又在10201中测试了一下,结果也是一样。你再看看:
-- session 1
SQL> select * from v$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

SQL> create table test1 as select rownum a from dual connect by rownum < 2;

表已创建。

SQL> select * from test1;

         A
----------
         1

SQL> set transaction read only;

事务处理集。


-- session 2
SQL> insert into test1 select rownum from dual connect by rownum < 4;

已创建3行。

SQL> commit;

提交完成。

SQL> select * from test1;

         A
----------
         1
         1
         2
         3

-- session 1
SQL> select * from test1;

         A
----------
         1


  发表评论



Copyright © 2001-2006 ChinaUnix.net All Rights Reserved

感谢所有关心和支持过ChinaUnix的朋友们
页面生成时间:0.02905

京ICP证041476号