Control Flow Statements
IF
Statement
- See in IF-statement
Single statement in IF
or ELSE
block
Follow
IF
andELSEIF
byTHEN
key word after the condition.Use
ENDIF
to end a wholeIF
block.
sql
IF [condition] THEN
[single_statement];
ELSEIF [condition] THEN
[single_statement];
ELSE
[single_statement];
END IF;
1
2
3
4
5
6
7
2
3
4
5
6
7
Multiple statements in IF
or ELSE
block
sql
IF [condition] THEN
BEGIN
[multiple_statements];
END
ELSEIF [condition] THEN
BEGIN
[multiple_statements];
END
ELSE
BEGIN
[multiple_statements];
END
END IF;
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
CASE
Statement
- See in CASE-statement
sql
CASE
WHEN [condition1] THEN
[body1];
WHEN [condition2] THEN
[body2];
...
ELSE [body];
END CASE;
CASE [value]
WHEN [match1] THEN
[body1];
WHEN [match2] THEN
[body2];
...
ELSE [body];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18