SYS用户设置serializable事务和read only事务无效

Oracle官方文档:http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_10005.htm

SET TRANSACTION

READ ONLY

The READ ONLY clause establishes the current transaction as a read-only transaction. This clause established transaction-level read consistency.

All subsequent queries in that transaction see only changes that were committed before the transaction began. Read-only transactions are useful for reports that run multiple queries against one or more tables while other users update these same tables.

This clause is not supported for the user SYS. Queries by SYS will return changes made during the transaction even if SYS has set the transaction to be READ ONLY.

 

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

reference:http://fxz-2008.javaeye.com/blog/836406

 

Oracle允许在事务开始时使用语句来设定事务的级别,以下三个语句分别设定oracle的三种事务隔离级别:

set transaction isolation level read committed;

set transaction isolation level serializable;

set transaction read only;

Plsql事务处理的语句有下列一些:

Commit, rollback, savepoint, rollback to savepoint, set transaction ,lock table等。

例如:

Set transaction read only

这个语句建立一个事务级的读一致性,事务内所有的查询所见的都是事务开始之前的改变,只读事务对于表有修改的许多查询报表来说比较有用。这个语句不适用于SYS用户,意味着,即使SYS用户设置事务为只读,查询也会返回事务期间的更改。

测试:

Scott用户下:

Session1

SQL> set transaction read only;

Transaction set

SQL> select sum(sal) from scott.emp ;

 SUM(SAL)

----------

  28124.2

 

Session2

SQL> update scott.emp a set a.sal = a.sal + 1.1;

14 rows updated

SQL> commit;

Commit complete


Session1

SQL> select sum(sal) from scott.emp ;

 SUM(SAL)

----------

  28124.2

SQL> commit;

Commit complete

SQL> select sum(sal) from scott.emp ;

 SUM(SAL)

----------

  28139.6

很容易看出set transaction read only的效果,如果实在sys下面,情况则是这样的:

Session1

SQL> set transaction read only;

Transaction set

SQL> select sum(sal) from scott.emp ;

 SUM(SAL)

----------

  28139.6

Session2

SQL> update scott.emp a set a.sal = a.sal + 1.1;

14 rows updated

SQL> commit;

Commit complete

SQL>

Session1

SQL> select sum(sal) from scott.emp ;

 SUM(SAL)

----------

    28155

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值