码迷,mamicode.com
首页 > 数据库 > 详细

mysql 游标的使用方法

时间:2016-04-11 18:40:45      阅读:256      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!