MySQL Stored Procedure cursor operation jumps out and continues

Source: Internet
Author: User

This article will introduce you to some problems encountered during the jump and continuation of the MySQL Stored Procedure cursor operation. Let's take a look at the solutions to this problem.

Recently, this problem occurs. During the MySQL stored procedure, you need to execute a conitnue operation during the cursor operation. as we all know, there are three commonly used cursor LOOP operations in MySQL: LOOP, REPEAT, WHILE. there are three cycles in the same way. I have never used it before, so write it down for future reference.

1. REPEAT

The Code is as follows: Copy code

REPEAT
Statements;
UNTIL expression
END REPEAT
Demo
DECLARE num INT;
DECLARE my_string VARCHAR (255 );
REPEAT
SET my_string = CONCAT (my_string, num ,',');
SET num = num + 1;
UNTIL num <5
End repeat; 2. WHILE


WHILE expression DO
Statements;
END WHILE
Demo
DECLARE num INT;
DECLARE my_string VARCHAR (255 );
SET num = 1;
SET str = '';
WHILE num <span> 10DO
SET my_string = CONCAT (my_string, num ,',');
SET num = num + 1;
End while; 3. LOOP (here there is a very important ITERATE, LEAVE)


DECLARE num INT;
DECLARE str VARCHAR (255 );
SET num = 1;
SET my_string = '';
Loop_label: LOOP
IF num <10 THEN
LEAVE loop_label;
ENDIF;
SET num = num + 1;
IF (num mod3) THEN
ITERATE loop_label;
ELSE
SET my_string = CONCAT (my_string, num ,',');
ENDIF;
End loop;


PS: it can be understood that ITERATE is the common contiune in our program, and ITERATE is the break. Of course, in the MySQL stored procedure, there must be a name in the loop structure, and everything else is the same.

About: mysql Stored Procedure cursor and multi-cursor instance

 

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.