How to use MySQL Cursors

Source: Internet
Author: User

BEGIN/*Calculate User Commission total amount*/DeclareAmountprice,pays,rates,goodsprice DECIMAL (10,2)DEFAULT0;DECLAREFlag int,getUserId;#if (userlevel=1) ThenSELECT member_id to getUserId from 33hao_member where OpenID=open_idDeclareCUR cursor forSelect Commission1_rate Rates,commission1_pay pays,goods_price from 33hao_goods_common;DECLARE CONTINUEHANDLER forNot FOUND SET flag=1; SET Flag=0; OPEN cur; Repeatfetch cur into rates, Pays,Goodsprice;if(rates=NULL) Then set Amountprice=amountprice+pays;ELSESet Amountprice=amountprice+goodsprice*rates;End if; UNTIL FlagEndREPEAT; CLOSE cur;RETURNAmountprice;End

How to use MySQL Cursors

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.