为什么此程序不起作用?
DROP PROCEDURE IF EXISTS `incDate`;
CREATE PROCEDURE incDate(@fromdate date, @enddate date)
REPEAT
SET @fromdate = date_add(@fromdate, INTERVAL 1 DAY);
INSERT INTO `dentists`.`dayT` (`day`) VALUES (@fromdate);
UNTIL @fromdate > @enddate END REPEAT;
END
MySQL只是给出此错误:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@fromdate date, @enddate date)
最佳答案
您缺少BEGIN
语句。尝试这个:
DROP PROCEDURE IF EXISTS `incDate`;
CREATE PROCEDURE incDate(@fromdate date, @enddate date)
BEGIN
REPEAT
SET @fromdate = date_add(@fromdate, INTERVAL 1 DAY);
INSERT INTO `dentists`.`dayT` (`day`) VALUES (@fromdate);
UNTIL @fromdate > @enddate END REPEAT;
END
关于mysql - 带重复循环的date_add过程,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17505735/