Operating in the MySQL database also has a circular statement operation, the standard loop mode: While loop, loop loop, and repeat loop.
There is also a non-standard loop: Goto. It is not recommended to use because the jump in goto statements can cause confusion in the mind used.
The format of these loop statements is as follows:
While ... Do ... END while
REPEAT ... UNTIL END REPEAT
LOOP ... END LOOP
Goto.
At the moment I only tested the while loop:
Delimiter $$//definition terminator is $$
drop procedure if exists wk; Delete an existing stored procedure
CREATE PROCEDURE wk ()//Creating a new stored procedure
Begin
declare i int; Variable declaration
Set i = 1;
While I < one do//loop body
INSERT into User_profile (UID) values (i);
Set i = i +1;
End while;
End $$//Ending definition statement
Call
delimiter; First, return the Terminator to;
Call WK ();
Delimter:mysql the default delimiter is; Tell the MySQL interpreter if the command is over and MySQL can execute it.
The purpose of using the delimiter redefinition Terminator here is to not let the statements in the stored procedure be output at the time of definition. (Script Academy Www.jbxue.com)
The simple syntax for creating a MySQL stored procedure is:
CREATE PROCEDURE Stored Procedure name ([in | out | inout] parameter)
BEGIN
Mysql statement
END
To call a stored procedure:
Call stored procedure name ()//name appended ()
<span style= "Color:rgb (57, 57, 57); Font-family:verdana, ' Ms Song ', Arial, Helvetica, Sans-serif; font-size:14px; line-height:21px; Background-color:rgb (250, 247, 239); " > Second, REPEAT cycle </span>
<pre name= "code" class= "HTML" >delimiter//
drop procedure if exists looppc;
CREATE PROCEDURE LOOPPC ()
Begin
declare i int;
Set i = 1;
Repeat
INSERT into User_profile_company (UID) values (i+1);
Set i = i + 1;
Until I >= 20
End repeat;
End//
----Call
Call LOOPPC ()
Third, Loop loop
Delimiter $$
drop procedure if exists lopp;
CREATE PROCEDURE Lopp ()
Begin
declare i int;
Set i = 1;
Lp1:loop//LP1 the loop body name loop as the keyword INSERT into user_profile (UID) values (i);
Set i = i+1;
If i >
Leave LP1; Leave the Loop body
End If;
End LOOP; End Loop
End $$