gpt4 book ai didi

mysql - 我的游标程序不起作用

转载 作者:可可西里 更新时间:2023-11-01 08:20:30 25 4
gpt4 key购买 nike

我有下一个程序:

BEGIN
DECLARE retribAn INTEGER DEFAULT 0;
DECLARE cPost INTEGER(11);
DECLARE done INT DEFAULT 0;
DECLARE curTipo CURSOR FOR
SELECT RETRIBUCION_ANUAL*1.05 AS RET_AN
FROM EMPLEADOS
WHERE ID_CPOSTAL%2=0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN curTipo;
REPEAT
FETCH curTipo INTO retribAn, cPost;
IF NOT done THEN
UPDATE EMPLEADOS
SET RETRIBUCION_ANUAL=retribAn
WHERE ID_CPOSTAL%cPost;
END IF;
UNTIL done END REPEAT;
CLOSE curTipo;
END

当我执行它时,sql 管理器输出:

Incorrect number of FETCH variables

我不明白为什么。

我是mysql的菜鸟=D,对不起我的英语。

谢谢

最佳答案

您在游标查询中只选择了一列并将数据提取到 FETCH 中的两个变量中

试试这个

BEGIN
DECLARE retribAn INTEGER DEFAULT 0;
DECLARE cPost INTEGER(11);
DECLARE done INT DEFAULT 0;
DECLARE curTipo CURSOR FOR
SELECT RETRIBUCION_ANUAL*1.05 AS RET_AN
FROM EMPLEADOS
WHERE ID_CPOSTAL%2=0;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;
OPEN curTipo;
REPEAT
FETCH curTipo INTO retribAn; --remove cPost here
IF NOT done THEN
UPDATE EMPLEADOS
SET RETRIBUCION_ANUAL=retribAn
WHERE ID_CPOSTAL%cPost = 0; --change this to value you want to check
END IF;
UNTIL done END REPEAT;
CLOSE curTipo;
END

关于mysql - 我的游标程序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14303200/

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