zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mysql 游标的使用方法

mysql方法 游标 使用
2023-09-11 14:19:35 时间
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