首页 > 数据库技术 > 详细

mysql 游标的使用方法

时间:2016-04-11 18:39:17      阅读:205      评论:0      收藏:0      [点我收藏+]
BEGIN
/*计算用户提成总金额*/
declare amountPrice,pays,rates,goodsPrice DECIMAL(10,2) DEFAULT 0;
DECLARE  flag int,getUserId;
#if(userlevel=1) then

SELECT  member_id into getUserId  from 33hao_member where openid=open_id

declare cur cursor for  select commission1_rate rates,commission1_pay pays,goods_price from 33hao_goods_common;
 DECLARE CONTINUE HANDLER FOR NOT FOUND SET flag=1;
    SET flag=0;
OPEN cur;
REPEAT
FETCH cur into rates,pays,goodsPrice;

if(rates=null) then
  set amountPrice=amountPrice+pays;
ELSE
   set  amountPrice=amountPrice+goodsPrice*rates;
end if;

UNTIL flag end REPEAT;

CLOSE cur;
RETURN  amountPrice;
end

 

mysql 游标的使用方法

原文:http://www.cnblogs.com/fogwang/p/5379076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!