Recently encountered such a problem, in the MySQL stored procedure, the cursor operation, you need to perform a conitnue operation. As we all know, there are three kinds of cursor loops in MySQL, loop,repeat,while three loops, the same way. Never used before, So write it down and make it easier to consult later.
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 (which has very important iterate,leave) DECLARE num INT; DECLARE str VARCHAR (255); SET num = 1; SET my_string = '; Loop_label:loop IF Num <10then 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: This can be understood iterate is our program commonly used in Contiune, and iterate is break. Of course, in the MySQL stored procedure, you need to have a name for the loop structure, all the others are the same.
About: Cursors and multiple-cursor instances in MySQL stored procedures