Flow Control Functions

This section describes 4 types of flow control functions: CASE ... WHEN, CASE WHEN, IF and IFNULL.

MySQL supports 4 types of flow control functions, which return values based on some conditions.

"CASE value WHEN val_1 THEN res_1 WHEN val_2 THEN res_2 ... ELSE res_0 END" - Returns res_1 if value matches val_1, or res_2 if value matches val_2, ..., or res_0 if value matches none of the given values.

"CASE WHEN con_1 THEN res_1 WHEN con_2 THEN res_2 ... ELSE res_0 END" - Returns res_1 if con_1 is true, or res_2 if con_2 is true, ..., or res_0 if none of the given conditions is true.

"IF(condition, res_1, res_2)" - Returns res_1 if condition is true, otherwise returns res_2.

"IFNULL(res_1, res_2)" - Returns res_1 if res_1 is not null, otherwise returns res_2.

Last update: 2015.

Table of Contents

 About This Book

 Introduction of SQL

 MySQL Introduction and Installation

 Introduction of MySQL Programs

 Perl Programs and MySQL Servers

 PHP Programs and MySQL Servers

 Java Programs and MySQL Servers

 Datatypes and Data Literals

 Operations and Expressions

 Character Strings and Bit Strings

Commonly Used Functions

Flow Control Functions

 Character String Functions

 Numeric Functions

 Date and Time Functions

 Cast Function

 Table Column Types for Different Types of Values

 Using DDL to Create Tables and Indexes

 Using DML to Insert, Update and Delete Records

 Using SELECT to Query Database

 Transaction Management and Isolation Levels

 Locks Used in MySQL

 Defining and Calling Stored Procedures

 Variables, Loops and Cursors Used in Stored Procedures

 Outdated Tutorials

 References

 PDF Printing Version