具有重复循环的date_add过程

时间:2013-07-06 18:11:54

标签: mysql sql date datetime

为什么这个程序不起作用?

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)

1 个答案:

答案 0 :(得分:2)

您缺少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