首页新闻找找看学习计划

mysql 存储过程并发得到相同的值

0
悬赏园豆:100 [已关闭问题] 关闭于 2017-03-16 20:33
复制代码
BEGIN
DECLARE sequenceIndex INT DEFAULT 0;
DECLARE curdate DATE DEFAULT CURDATE();
START TRANSACTION;
SELECT
    sequence INTO sequenceIndex
FROM
    ordersequence
WHERE
    CurrentDay = curdate;

IF sequenceIndex = 0 
THEN
INSERT INTO ordersequence (CurrentDay, sequence)
VALUES
    (CURDATE(), 1);
ELSE
UPDATE ordersequence
SET sequence = sequence+1
WHERE
    CurrentDay = curdate;
END
IF;
COMMIT;
SELECT sequenceIndex FROM ordersequence WHERE
    CurrentDay = curdate FOR UPDATE;
END
复制代码

 用这个存储过程产生的种子号生成的字符串。出现了重复

我这个存储过程并发大的时候可能会select到会得到相同的sequenceIndex,是为什么。想不太明白...  select写在事物的外面里面都一样。是不是要加锁?
Shenroe的主页 Shenroe | 菜鸟二级 | 园豆:202
提问于:2017-03-16 20:12
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册