数据库有四种隔离级别:read uncommited,read commited, repeatable read,phantom read
oracle提供三种隔离级别:read commited, serializable, read only
在oracle怎么实现repeatable read 呢?
select for update保证在读取数据时改数据不能被改写,从而保证一致读。
给两次读限定在同一个事物中, 利用oracle的consistent read 也可以保证一致读。
Transaction A | ransaction B |
1>Begin | |
2>select * from test where id>=2 for update; | |
3>update test set id=3 where id=2; hang |
|
4>select * from test where id>=2; | |
5>commit |
但是这并不能保证幻像读的出现。
Transaction A | ransaction B |
1>Begin | |
2>select * from test where id>=2 for update; | |
3>insert into test values(3); commit; |
|
4>select * from test where id>=2; | |
5>commit |
因此oracle引入了serilizable的事物级别。 因为该级别加入了读锁(range--lock)和写锁。 但如果其他事物不会影响到本事物的读或些的数据, 其他事物可以读该数据。
read-only是数据只能读不能写。 相当于静态数据,无疑隔离级别高。 但应用范围很小。