mysql存储过程使用

每行n的指定字段都加上n*6天的时间

DELIMITER $$
CREATE PROCEDURE GIFT()
   BEGIN
      DECLARE a INT Default 13 ;
      DECLARE d INT Default 0 ; 
      DECLARE n INT Default 0 ; 
      simple_loop: LOOP
         SET a=a+1;
                 SET d=(d+1);
                 SET n = d*6*86400
                 SET @s = CONCAT("UPDATE user_giftcode SET btime=btime+", convert(n, char), ", etime=etime+", convert(n, char), " WHERE channel='a",convert(a, char),"'");
                 SELECT @s;
         PREPARE stmt3 FROM @s;
         EXECUTE stmt3;
         IF a=111 THEN
             LEAVE simple_loop;
         END IF;
   END LOOP simple_loop;
END $$
call GIFT()

你可能感兴趣的:(mysql存储过程使用)