0

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

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)
4

1 回答 1

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
于 2013-07-06T18:13:44.497 回答