无法串行访问事务错误:ORA-08177: can't serialize access for this transaction

来源:互联网 发布:苹果手机数据流量开关 编辑:程序博客网 时间:2024/06/07 04:06

当事务隔离级别为serializable,两个事务并发修改同一个对象,当前一个事务提交或回滚时,第二个事务会收到该错误。

 

测试使用表,此表用于生成唯一主键:

 

test@ORCL> create table id_table
  2  (id_name varchar2(30) primary key,
  3  id_value number);

Table created.

 

test@ORCL>insert into id_table values('MY_KEY',0);

1 row created.

 

test@ORCL>commit;

Commit complete.

 

 

会话一事务隔离级别serializable,修改id_table表中MY_KEY值加1,但不提交

 

test@ORCL>set transaction isolation level serializable;

Transaction set.

 

会话二事务隔离级别serializable,修改id_table表中MY_KEY值加1,但不提交

 

test@ORCL>set transaction isolation level serializable;

Transaction set.

 

test@ORCL>update id_table  set id_value = id_value + 1 where id_name ='MY_KEY';

 

此时修改会被阻塞

 

会话一提交修改的数据,会话二会收到如下信息

 

 

test@ORCL>update id_table set id_value = id_value + 1 where id_name = 'MY_KEY';
update id_table set id_value = id_value + 1 where id_name = 'MY_KEY'
       *
ERROR at line 1:
ORA-08177: can't serialize access for this transaction

 

 

 

 

 

原创粉丝点击