gpt4 book ai didi

mysql。存储过程错误 1328

转载 作者:行者123 更新时间:2023-11-29 02:43:10 25 4
gpt4 key购买 nike

这真的让我很困惑。我正在将一个简单的过程从 informix 转换为 mysql。它基本上所做的是通过事件表和日历表告诉我下一个事件是什么。在 informix 中,过程很简单。

FOREACH
SELECT date,weekno,event
INTO l_date,l_week,l_event
FROM event,calendar
WHERE dayno = dayno
AND date = l_today
AND start >= l_now
UNION
SELECT date,weekno,event
FROM event,calendar
WHERE dayno = dayno
AND date > l_today
UNION
SELECT TODAY,9999,9999
FROM event,calendar
WHERE dayno = dayno
AND event = (SELECT MAX(event) FROM event)
ORDER BY 3

if l_event = 9999 then <error> end if;
EXIT FOREACH
END FOREACH

所以基本上查询会找到下一个事件并返回它。 l_today 和 l_event 是传递的参数。所以到 mysql 版本。

looper: BEGIN
DECLARE curs1 CURSOR FOR
SELECT CONCAT("SELECT date, weekno, event FROM event INNER JOIN calendar ON dayno = dayno",
" WHERE date = '", lv_today ,"' AND start >= '", lv_time ,"'",
" UNION SELECT date, weekno, event FROM event INNER JOIN calendar ON dayno = dayno WHERE date > '", lv_today ,"'",
" UNION SELECT DATE(NOW()) AS date, 9999 AS weekno, 9999 AS event FROM event INNER JOIN calendar ON dayno = dayno",
" WHERE (SELECT MAX(event) FROM event) ORDER BY event ");

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;

OPEN curs1;
loop1: LOOP
FETCH curs1 INTO ldate, lweek, levent;
SELECT ldate, lweek, levent;
LEAVE looper;
END LOOP loop1;
END;

我没有检查其余方法是否有效,因为我收到此错误:

  1. Incorrect number of FETCH variables.

这是否意味着我为每个查询返回声明了一个不同的变量?我是 mysql 的新手。如果是这种情况,解决这个难题的最佳方法是什么?我还更改了列名和表名。

非常感谢

最佳答案

looper: BEGIN
DECLARE curs1 CURSOR FOR
SELECT eve_date, dia_weekno, eve_event
FROM game_event
INNER JOIN stan_calendar ON eve_abs_dayno = dia_abs_dayno
WHERE eve_date = lv_today
AND eve_start >= lv_time
UNION
SELECT eve_date, dia_weekno, eve_event
FROM game_event
INNER JOIN stan_calendar ON eve_abs_dayno = dia_abs_dayno
WHERE eve_date > lv_today
UNION SELECT DATE(NOW()) AS eve_date, 9999 AS dia_weekno, 9999 AS eve_event
FROM game_event
INNER JOIN stan_calendar ON eve_abs_dayno = dia_abs_dayno
WHERE (SELECT MAX(eve_event) FROM game_event) ORDER BY eve_event;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done := TRUE;

OPEN curs1;

curs_loop: LOOP
FETCH curs1 INTO lv_date, lv_week, lv_event;

SELECT lv_date, lv_week, lv_event;
LEAVE looper;

CLOSE curs1;
END LOOP curs_loop;

谢谢你回答我的问题,我已经把它恢复到我认为的样子......现在它可以工作了。这是完整的循环。

关于mysql。存储过程错误 1328,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47265436/

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