MySQL cursor loop example _ MySQL-mysql tutorial

Source: Internet
Author: User
MySQL cursor loop example bitsCN.com


MySQL cursor loop example

If you use the in statement, it feels very slow and there is no result after running for a long time. you can use the stored procedure to delete it.

Progress. this is the sample code of MySQL cursor loop. it can be recorded frequently in the future.

Create definer = 'root' @ '%' PROCEDURE 'bi'. 'clean _ data '()

READS SQL DATA

BEGIN

Declare v_imei varchar (128 );

Declare stop int default 0;

Declare cur cursor for (select imei from bi. tmp_imei );

Declare continue handler for sqlstate '200' SET stop = 1;

OPEN cur;

FETCH cur INTO v_imei;

WHILE stop <> 1 DO

Delete from bi. tmp_dt_fee_user_info where imei = v_imei;

FETCH cur INTO v_imei;

End while;

CLOSE cur;

END

BitsCN.com
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.