有人帮我在这里为什么在我的商店程序中得到错误

时间:2018-05-30 19:39:42

标签: mysql stored-procedures

我试图在特定的给定日期rane中插入日期范围表中的所有日期。这是我的程序,但我收到错误,我无法解决它。

   DELIMITER//  
   CREATE PROCEDURE example(IN sdate DATE, IN enddate DATE)  
   BEGIN  
   SET @sdate = sdate;
   SET @enddate=enddate;

   WHILE(@sdate < @enddate) DO
   INSERT INTO daterange SET day = sdate;
   sdate = DATE_ADD(sdate, INTERVAL 1 DAY);   
   END WHILE;

   SELECT * FROM daterange;

   END//;  
   DELIMITER ;  

1 个答案:

答案 0 :(得分:0)

尝试在Delimiter中输入空格和// 而你的同时有语法错误,请看修复程序:

DELIMITER //  
CREATE PROCEDURE example(IN sdate DATE, IN enddate DATE)  
BEGIN  

declare varDay date;

WHILE(sdate < enddate) DO

    INSERT INTO daterange ([your-column]) values (varDay);

    SET sdate = DATE_ADD(sdate, INTERVAL 1 DAY);    
    SET varDay = sdate;
END WHILE;

SELECT * FROM daterange;

END //;  
DELIMITER ;