我有一条CASE
语句,它接收表的前40条记录,它具有基于计数器的不同过程 - @COUNT
。不幸的是,当我在没有 a 的情况下运行该程序时,else
它不起作用并给出Case not found for CASE statement (Error 1339)
.
但是当我确实有 else 它工作正常但它在最后一天运行两次,所以我有一个最后日期的副本。
这有什么原因吗?请检查我下面的代码..很多已被删除
CREATE PROCEDURE `init`(In dID INT)
BEGIN
DECLARE first40 CURSOR FOR
SELECT * FROM tbl
WHERE tbl.id = dID
ORDER BY tbl.datum ASC
LIMIT 40;
OPEN first40;
SET @COUNT = 0;
REPEAT FETCH first40 INTO Tid, Tdt, Tcls, Thgh, Tlw, Tvol, Tnms_id;
SET @COUNT = @COUNT + 1;
CASE
WHEN @COUNT = 1 THEN
WHEN @COUNT>= 2 AND @COUNT < 9 THEN
WHEN @COUNT = 9 THEN
WHEN @COUNT >= 10 AND @COUNT < 12 THEN
WHEN @COUNT = 12 THEN
WHEN @COUNT = 13 THEN
WHEN @COUNT = 14 THEN
WHEN @COUNT = 15 THEN
WHEN @COUNT = 16 THEN
WHEN @COUNT >= 17 AND @COUNT < 20 THEN
WHEN @COUNT >= 20 AND @COUNT < 26 THEN
WHEN @COUNT = 26 THEN
WHEN @COUNT >= 27 AND @COUNT < 34 THEN
WHEN @COUNT = 34 THEN
WHEN @COUNT > 34 AND @COUNT <= 40 THEN
END CASE;
INSERT INTO .....
VALUES ....;
UNTIL done END REPEAT;
CLOSE first40;
END