gpt4 book ai didi

MySQL存储过程INSERT问题

转载 作者:行者123 更新时间:2023-11-29 12:53:26 25 4
gpt4 key购买 nike

适用以下场景:

CREATE TEMPORARY TABLE IF NOT EXISTS `smth_table` (
`login` VARCHAR(20),
`password` VARCHAR(20),
`type` INT(11),
`account_state` DECIMAL(12,4)
);

PREPARE Selection FROM
"INSERT INTO `smth_table`
(SELECT ta.`login`, ta.`password`, ta.`type`, ta.`account_state`
FROM tableA ta
INNER JOIN tableB tb ON tb.id_client = ta.id_client
WHERE tb.id_lot = ? AND ta.`type` MOD 2 = 0
AND ta.first_use = '0000-00-00 00:00:00'
AND ta.account_state = 0
LIMIT ?)";
SET @WHERE = var1;
SET @LIMIT = var2;
EXECUTE Selection USING @WHERE, @LIMIT;
DEALLOCATE PREPARE Selection;

DECLARE curs CURSOR FOR
SELECT `password` FROM `smth_table`;

DECLARE CONTINUE HANDLER
FOR NOT FOUND SET v_finished = 1;


OPEN pin_curs;

get_pass: LOOP
FETCH curs INTO pass;
IF v_finished = 1 THEN
LEAVE get_pass;
END IF;

UPDATE tableA ta INNER JOIN tableB tb
ON tb.id_client = ta.id_client
SET `type` = `type` | 1,
`account_state` = `account_state` + 5
WHERE tb.id_lot = var1
AND `password` = pass;


END LOOP get_pass;

CLOSE curs;

END

为什么当我运行此存储过程时,临时表中填充的内容是否超过限制?请记住,我使用通过过程传递的 IN 变量设置了 LIMIT,顺便说一句,它是 10。但是当我运行该过程时,它会在临时表中插入更多 100 行,我不明白为什么,它应该只插入 10 行。

最佳答案

已解决!

该问题源于这样一个事实:我在再次创建表时没有删除该表,因此一遍又一遍地插入相同的值...

DROP TABLE IF EXISTS `smth_table`; 

这是在创建它之前插入的,并且查询运行顺利:-)

关于MySQL存储过程INSERT问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24426903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com