oracle 设置不可重复,oracle – 不可重复读和幻读之间有什么区别?

From Wikipedia(其中有很棒的和详细的例子):

A non-repeatable read occurs, when during the course of a transaction, a row is retrieved twice and the values within the row differ between reads.

A phantom read occurs when, in the course of a transaction, two identical queries are executed, and the collection of rows returned by the second query is different from the first.

简单示例:

>用户A运行同一个查询两次。

>在其间,用户B运行事务并提交。

>不可重复读:用户A已查询的A行第二次有不同的值。

>幻像读取:查询中的所有行之前和之后都具有相同的值,但正在选择不同的行(因为B已删除或插入一些行)。示例:从表中选择sum(x)将返回不同的结果,即使没有受影响的行本身已更新,如果行已添加或删除。

In the above example,which isolation level to be used?

您需要什么隔离级别取决于您的应用程序。 “更好”的隔离级别(例如降低的并发性)具有高成本。

在您的示例中,您不会有幻像读取,因为您只选择单个行(通过主键标识)。你可以有不可重复的读取,所以如果这是一个问题,你可能想要有一个隔离级别,以防止。在Oracle中,事务A也可以发出SELECT FOR UPDATE,然后事务B不能更改行,直到A完成。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值