mysql函数+定时器

来源:互联网 发布:世宗大王级驱逐舰知乎 编辑:程序博客网 时间:2024/05/21 00:00

1)函数

BEGIN# 给每个类目VIP购买数量随机增加1-3DECLARE done INT DEFAULT 0 ;             -- 游标开关DECLARE randNum INT DEFAULT 0 ; -- 随机数DECLARE sellCount INT DEFAULT 0 ; -- 购买数量DECLARE groupBuyId INT default 0; -- DECLARE groupBuying CURSOR FOR SELECT t.id FROM tableName t WHERE t.group_type = 4 AND t.`status` = 1 AND NOW() >= t.start_time AND NOW() <= t.end_time;  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1 ;  OPEN groupBuying ;  read_loop :LOOP    FETCH groupBuying INTO groupBuyId ;IF done = 1     THEN LEAVE read_loop ;    END IF ;SELECT t.sell_count INTO sellCount FROM tableName t WHERE t.id = groupBuyId;set randNum = ceiling(rand()* 3) + sellCount;UPDATE tableName b SET b.sell_count = randNum WHERE b.id = groupBuyId;END LOOP ;CLOSE groupBuying ;RETURN 1;END


2)定时器






原创粉丝点击