MySQL base - flow control structures

A branch structure

Select a program from the two or more paths to carry

1.if function

Function: a simple two-branch

grammar:

if (expression 1, expression 2, expression 3)

The order of execution:

If the expression 1 holds, if the function returns the value of the expression 2, otherwise the return value of the expression 3

2.case structure

● a case where: in similar java switch statement is generally used to achieve equivalent Analyzing

grammar:

the case variable | expression | fields
when determining a value to 1 then returns a value of 1 or statement;
values to be determined when the value of 2 or 2 then return statement 2;
...
the else to return the value of n or n statement;
end case;

● Case 2: Multiple similar java in the if statement, for implementing the general determination section

grammar:

Case
When determination conditions to 1 then returns a value of 1 or statement;
value When the determination conditions for 2 then returns or statement 2 2;
...
value n or else to return statement n;
End Case;

Features:

1. As can be expressions, statements nested in the other, can be placed anywhere, or begin end begin end inside out.
2. You can go as a separate statement, it can be placed only begin end in.
3. If the value is satisfied when the condition is satisfied or, the latter corresponding to the then statement is executed, and ends Case, if not met, or else the value of the execution statement
4.else may be omitted, if else is omitted, and when all the conditions are not met, null is returned.

Case:

3.if structure

Function: Multi-branch
grammar:

if condition 1 then statement. 1;
else if conditional statement 2 then 2;
...
[n-else statement;]
end if;

Applications: Application to begin end in

Case:

Second, the loop structure

Procedure on the basis of certain conditions, implementation of a code repeat

Loop control:

iterate similar to continue to continue to the end of this cycle, continue to the next.
leave similar to break out of, where the end of the current cycle.

1.while

Syntax: first determine, after execution

[Label:] conditions do while loop
loop;
End tag [while];

Case:

● no added loop control statements

● Add leave loop control statements

● Add iterate loop control statements

2.loop

grammar:

[Label:] loop
loop;
End tag [loop];

It can be used to simulate a simple infinite loop

3.repeat

Syntax: first execution after judgment

[Label:] repeat
loop;
an until loop end condition
end repeat [label];

Case:


Guess you like

Origin www.cnblogs.com/nnadd/p/12578267.html