+ -
当前位置:首页 → 问答吧 → MYSQL局部变量的怪异问题

MYSQL局部变量的怪异问题

时间:2011-12-26

来源:互联网

SQL code

DECLARE fanty int DEFAULT 0;
DECLARE b int DEFAULT 0;

START TRANSACTION;

if 1=a then
 set fanty =1;
 set b =1;
else
 set fanty =2;
 set b =2;
end if

insert into s(fanty) values(fanty);

update t set c = c+b where type =fanty;

commit;



多并发执行上面这个存储,现在有个奇怪的问题,得到的结果fantyb不是一一对应的,这个是什么问题,求高手解析

作者: i03630211   发布时间: 2011-12-26

用的什么引擎?事务隔离级多少?

作者: iihero   发布时间: 2011-12-26

update t set c = b where type =fanty;改成这样试试,以为不知道原始的c的值是多少

作者: rucypli   发布时间: 2011-12-26

innodb 的 REPEATABLE READ锁

作者: i03630211   发布时间: 2011-12-26

引用 2 楼 rucypli 的回复:

update t set c = b where type =fanty;改成这样试试,以为不知道原始的c的值是多少

c是一个字段名

作者: i03630211   发布时间: 2011-12-26

在替换前LOCK试试
LOCK TABLES t WRITE
update t set c = c+b where type =fanty;
UNLOCK TABLES

 

作者: wwwwb   发布时间: 2011-12-26