需求如下: 
    数据库是mysql,写个存储过程从表tb_accountinfo中取出所有计费模式(aipolicyfee)为包月的用户,从用户金额(aibalance)中扣去月租,月租当参数在页面调用此存储过程是传入。 DELIMITER $$DROP PROCEDURE IF EXISTS `bosscn`.`pr_kouyuezu` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `pr_kouyuezu`(input decimal(10,2))
BEGINDECLARE done INT DEFAULT 0;
declare bal decimal(10,2);
declare id varchar(45);
declare id1 varchar(45);
declare rtn int;Declare curDecFee Cursor
  for
  Select aiid From tb_accountinfo where aipolicyfee = '包月';DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;set bal = 0;Open curDecFee;repeatFetch  curDecFee Into id;Select aibalance into bal From tb_accountinfo Where aiid=id;
set bal = bal - input;if bal >= 0 then
update tb_accountinfo set aibalance = bal where aiid = id;
else
set rtn = 0;
end if;UNTIL done end repeat;close curDecFee;END $$DELIMITER ;问题:表中前面包月用户扣费正常,最后一个包月用户总是多扣一次,请问为什么,有什么比较好的解决办法,谢谢!