存储过程游标学习
CREATE DEFINER=`root`@`%` PROCEDURE `insertmoney`()
BEGIN
	declare i int DEFAULT 0;
  declare userid varchar(32);
  declare money decimal(19,2); 
  DECLARE done INT DEFAULT 0;
  declare TEST cursor for select user_code,sum(account_money+violate_money-derate_money) as money from t_charge_billing where state=0 and delete_flag=0 GROUP BY user_code;
	declare continue handler for not found set done=1; -- 没有下一条数据 修改标记为1
  OPEN TEST;
	fetch test into userid,money;
   while done<>1 do
			set money=money+1;
  		update t_charge_account set money =money where user_id in (select id from biz_water_user where code=userid);
			fetch test into userid,money;
	end while;
 CLOSE TEST;
END
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号