Write a simple stored procedure

   - the MySQL circulating in the three while, loop, repeat seeking 1-n and 


   - a first loop while 
   - seeking and 1-n 
   / *   while loop syntax: 
   while conditions DO 
               loop; 
   End while; 
   * / 
    Create  Procedure add_calendar (a int ) 
     the begin 
        DECLARE I int  default  . 1 ;
     the while I <= a the DO - cycle start 
                the INSERT  the iNTO Calendar (datelist) the VALUES ( 
      ADDDATE ( 
          (    - here, start date, you can replace the current date
              The DATE_FORMAT ( " 2019 - . 1 - . 1 ", ' %% Y-M-% D ' ) 
          ), 
          I 
     )); 
        SET I = I + . 1 ;
     End  the while ; - end of the loop 
    End ;
     - executing the stored procedure 
    call add_calendar ( 10000 );
     - delete the stored procedure 
    drop  procedure  IF  EXISTS add_calendar;

 

Guess you like

Origin www.cnblogs.com/alittlesmile/p/11583764.html