The While statement usage method in the MSSQL and MySQL tutorial
While the level of use can help a little.
While Boolean_expression
{sql_statement | statement_block}
[Break]
{sql_statement | statement_block}
[Continue]
Parameters
Boolean_expression
Returns an expression of True or false. If a Boolean expression contains a SELECT statement, you must enclose the SELECT statement in parentheses.
{sql_statement | statement_block}
Transact-SQL statements or groups of statements defined with statement blocks. To define a statement block, use the control flow keyword begin and end.
Break
Causes the exit from the inner while loop. Any statements that appear after the end keyword will be executed, and the ending keyword is a circular closing tag.
Continue
Causes the while loop to restart execution, ignoring any statements after the Continue keyword
Article reprinted from the Home network: http://www.bitscn.com/pdb/mssql/201010/191381.html
Sample code:
The code is as follows:
DECLARE @a int
Set @a = 1
While @a<25
Begin
Insert into demotable (ID,ITEM1,ITEM2) VALUES (@a, "abc", "123")
Set @a = @a + 1
End
In MySQL, use a while loop to process data methods: You need to create a new stored procedure to call the Execute stored procedure directly.
Sample code:
The code is as follows:
Create definer= ' root ' @ ' localhost ' procedure ' newprocedure ' ()
Begin
declare i int;
Set I=1;
While i<100 do
Insert into demotable (ID,ITEM1,ITEM2) VALUES (i, "Test questions", "0");
Set i = i + 1;
End while;
End
Example Two
Mysql>
mysql> delimiter $$
Mysql>
Mysql> CREATE PROCEDURE MyProc ()
-& Gt Begin
-> declare i int;
-> set I=1;
-> loop1:while i<=10 do
-> if mod (i,2) <>0 then/*even number-try again*/
-> Select concat (i, "is a odd Number ");
-> End If;
-> set i=i+1;
-> End While Loop1;
-> end$$
Query OK, 0 rows Affected (0.00 sec)
Mysql>
Mysql> delimiter;
Mysql> call MyProc ();