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