[Ignore] MySQL control statements (if, loop, leave, iterate, while)

Source: Internet
Author: User
From: http://blog.chinaunix.net/space.php? Uid = 21144244 & Do = Blog & cuid = 1923636 Http://wwty.iteye.com/blog/698210 Let's first introduce the Oracle control statements.  

If ElseElsifWhile For Loop

The control statement in MySQL is:

 

If ElseElseifWhile LoopRepeatLeave Iterate

 

The following is an example:

Delimiter / /
Create Procedure pro
Begin
Declare @ A Int Default 5 ;
If @ A > 2 Then
Select @ A ;
Elseif @ A < 5 Then
Select 2 ;
End If ;
End
/ /

 

The following is the use of loop.

The use of loop should be combined with leave and iterate

I have probably guessed the name.

Leave means to exit the exit loop, while iterate means to continue iteration.

 

Delimiter / /
Create Procedure pro
Begin
Declare Int Default 1;
Label1: loop
If < 6 Then
Select A ;
Set A = A + 1 ;
Iterate label1 ;
End If ;
Leave label1 ;
End Loop label1 ;
End
/ /

The following is the repeat pull

 

Delimiter / /
Create Procedure pro
Begin
Declare Int Default 3 ;
Repeat
Select A ;
Set A = A + 1 ;
Untile > 5 End Repeat ;
End
/ /

 

The last one is the while statement.

delimiter / /
Create procedure pro
begin
declare a int default 4 ;
while a 10 DO
select A ;
set A = A + 1 ;
end while ;
end
/ /

 

From the example above, we can see that there is a big difference between Oracle and Oracle.

The value assignment is declared in the begin block through the set instead of the: = declaration variable through the declare.

 

Oracle has for statements and most of them are loop statements.

For I in 1 .. 5

Loop

Statement

End loop;

While a> 5

Loop

End loop;

 

Loop

Exit when ();

End Loop

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.