事务隔离级别

数据库中,读取数据时常见的几种情况:
Dirty Read:A transaction reads data that has been written by another transaction that has not been committed yet.
Fuzzy Read:A transaction rereads data it has previously read and finds that another committed transaction has modified or deleted the data.
Phantom Read:A transaction reruns a query returning a set of rows that satisfies a search condition and finds that another committed transaction has 
inserted additional rows that satisfy the condition.
上述文字可概括为:
1.脏读:读取未提交的数据;
2.模糊读:读取已变动的数据;
3.幻读:读取已提交的数据。

在oracle中,仅定义了两种级别的隔离等级,分别是READ COMMITTED、SERIALIZABLE。
------------------	------------------	------------------	------------------
Isolation Level		Dirty Read		Fuzzy Read		Phantom Read
------------------	------------------	------------------	------------------
READ COMMITTED		no			yes			yes
------------------	------------------	------------------	------------------
SERIALIZABLE		no			no			no
------------------	------------------	------------------	------------------
由上表可知,oracle是不允许脏读的。

举例:
--会话1
create table t_isolation(id integer,name varchar2(10));
insert into t_isolation(id,name) values (1,'a');
commit;

--会话2
set transaction isolation level read committed;
select * from t_isolation;

--会话1
--不提交
insert into t_isolation(id,name) values (2,'b');

--会话2
select * from t_isolation;
执行查询,发现查询不到刚插入的数据
update t_isolation set name='c' where id=2;
执行更新,发现无数据可更新
delete from t_isolation where id=2;
执行删除,发现无数据可删除

--会话1
commit;

--会话2
select * from t_isolation;
执行查询,发现可以查询到刚插入的数据
既然可查询到刚插入的数据,那么更新和删除自然也没问题,这里就不详细举例了。

--会话3
set transaction isolation level serializable;
select * from t_isolation;

--会话1
--不提交
delete from t_isolation where id=2;

--会话3
select * from t_isolation;
发现删除的数据可查询到

--会话1
commit;

--会话3
select * from t_isolation;
发现删除的数据可查询到

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值