DROP PROCEDURE IF EXISTS `insertManyDate`$$ CREATE DEFINER=`root`@`%` PROCEDURE `insertManyDate`(IN `beginDate` DATE,IN `endDate` DATE) BEGIN DECLARE nowdate DATE DEFAULT NOW(); DECLARE endtmp DATE DEFAULT NOW(); SET nowdate = DATE_FORMAT(beginDate,'%Y%m%d'); SET endtmp = DATE_FORMAT(endDate,'%Y%m%d'); WHILE nowdate<endtmp DO INSERT INTO dibao_day_loop(ymd) VALUES(nowdate); SET nowdate = DATE_ADD(nowdate,INTERVAL 1 DAY); END WHILE; END$$ DELIMITER ;
向表中插入指定日期范围的连续日期。
调用方式:
call insertManyDate(STR_TO_DATE('2019-06-12','%Y-%m-%d'),STR_TO_DATE('2019-12-19','%Y-%m-%d'))