在搜索了最近5个小时后,我无法弄清楚为什么这段代码不起作用......
如果我删除循环中的INSERT行,它确实可以正常工作???
我在Debian上使用Mysql 5.5。
请帮忙吗?提前谢谢。
SET @j = 0;
DELIMITER $$
CREATE PROCEDURE procedureYearWeek(INOUT j INT)
BEGIN
DELETE FROM Periods WHERE perPeriods NOT IN (0);
WHILE j < 10 DO
INSERT INTO Periods (perPeriods) VALUES (YEARWEEK(ADDDATE(CURRENT_DATE(), INTERVAL j DAY)));
SELECT j + 1 INTO j;
END WHILE;
END $$
DELIMITER ;
CALL procedureYearWeek(@j);
答案 0 :(得分:0)
对不起,原来是我对Mysql缺乏经验以及一个愚蠢的错误。 这就是答案:
DELIMITER $$
CREATE PROCEDURE procedureYearWeek()
BEGIN
DECLARE j INT DEFAULT 0;
DECLARE newDAta INT DEFAULT 0;
DELETE FROM Periods WHERE perPeriods NOT IN (0);
WHILE j < 10 DO
INSERT INTO Periods (perPeriods) VALUES (YEARWEEK(ADDDATE(CURRENT_DATE(), INTERVAL newDAta DAY)));
SET j = j + 1;
SET newDAta = newDAta + 14;
END WHILE;
END $$
DELIMITER ;