1IF (Expression 1)
2BEGIN
3 Statement 1;
4END
5
6ELSE IF (Expression 2)
7BEGIN
8 Statement 2;
9END
10..........
11ELSE
12BEGIN
13 Default Statement;
14END
1-- PL/SQL
2BEGIN
3 IF my_val = 1 THEN [...]
4 ELSE [...]
5 END IF;
6END;
7-- In a query (DUAL is for Oracle)
8SELECT CASE WHEN my_col = 1 THEN 'Ok' ELSE 'Ko' END AS my_result
9FROM DUAL;
1IF Boolean_expression
2BEGIN
3 -- Statement block executes when the Boolean expression is TRUE
4END
5ELSE
6BEGIN
7 -- Statement block executes when the Boolean expression is FALSE
8END
1IF 1=1
2 SELECT 1
3ELSE
4 SELECT 0
5-- returns 1
6
7-- Definition
8IF Boolean_expression
9 { sql_statement | statement_block }
10[ ELSE
11 { sql_statement | statement_block } ]
1SELECT CASE
2 WHEN A + B > C AND B + C > A AND A + C > B THEN
3 CASE
4 WHEN A = B AND B = C THEN 'Equilateral'
5 WHEN A = B OR B = C OR A = C THEN 'Isosceles'
6 ELSE 'Scalene'
7 END
8 ELSE 'Not A Triangle'
9 END
10FROM TRIANGLES;
11