mysql 游标中带赋值的

 

drop procedure if exists pro_initUserBirdCount;

DELIMITER $$
create procedure pro_initUserBirdCount()
BEGIN
declare uid int(10);
declare b int(10) default 0; /*是否达到记录的末尾控制变量*/
DECLARE cur_1 CURSOR FOR select distinct user_id from species_pedia.species_user_birds;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET b = 1;
OPEN cur_1;
FETCH cur_1 INTO uid; /*获取第一条记录*/
while b<>1 do
SET SQL_SAFE_UPDATES=0;/*此句很重要*/

set @count_birds=(select count(1) from species_pedia.species_user_birds where user_id=uid);
set @year_birds=(select count(1) from species_pedia.species_user_birds where user_id=uid and year=2014);

-- select @count_birds:=count(1) from g3db.node_bird nb ,g3db.node n where nb.NodeID=n.NodeID and nb.IsVerify=1 and n.UserID=uid;
-- select @year_birds:=count(1) from g3db.node_bird nb ,g3db.node n where nb.NodeID=n.NodeID and nb.IsVerify=1 and n.UserID=uid and nb.RecTimeYear=2016;

insert into species_pedia.species_users set user_id=uid,count_bird_species=@count_birds,year_bird_species=@year_birds;
FETCH cur_1 INTO uid; /*取下一条记录*/
END while;
close cur_1;
END$$
DELIMITER ;


call pro_initUserBirdCount();

转载于:https://www.cnblogs.com/RainLi/p/5336334.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值