In MySQL, you can use IF(), IFNULL(), NULLIF(), and ISNULL() functions to control the process. 1. Use of IF() functionIF(expr1, expr2, expr3) returns the value of expr2 if the value of expr1 is true, and returns the value of expr3 if the value of expr1 is false. SELECT IF(TRUE,'A','B'); -- Output: A SELECT IF(FALSE,'A','B'); -- Output: B 2. Use of IFNULL() functionIFNULL(expr1, expr2) returns the value of expr2 if the value of expr1 is null, and returns the value of expr1 if the value of expr1 is not null. Example 1 mysql> SELECT IFNULL(1,0); -> 1 mysql> SELECT IFNULL(NULL,10); -> 10 mysql> SELECT IFNULL(1/0,10); -> 10 mysql> SELECT IFNULL(1/0,'yes'); -> 'yes' Example 2 SELECT IFNULL(NULL,'B'); -- Output: B SELECT IFNULL('HELLO','B'); -- Output: HELLO 3. Use of NULLIF() functionNULLIF(expr1, expr2), if expr1=expr2, the return value is null, otherwise the return value is the value of expr1. SELECT NULLIF('A','A'); -- Output: null SELECT NULLIF('A','B'); -- Output: A 4. Use of ISNULL() functionISNULL(expr) returns 1 if the value of expr is null, and returns 0 if the value of expr1 is not null. SELECT ISNULL(NULL); -- Output: 1 SELECT ISNULL('HELLO'); -- Output: 0 This is the end of this article about the detailed usage of IF(), IFNULL(), NULLIF(), and ISNULL() functions in MySQL. For more information about IF(), IFNULL(), NULLIF(), and ISNULL() in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Detailed explanation of application scenarios of filters in Vue
>>: Two ways to manage volumes in Docker
1. Go to the GraphVis official website to downloa...
1. Export the database using the mysqldump comman...
Anyone who has used Windows Remote Desktop to con...
The establishment of MySQL index is very importan...
This is to commemorate the 4 pitfalls I stepped o...
How to uninstall MySQL database under Linux? The ...
Responsive layout systems are already very common...
In MySQL, you may encounter the problem of case s...
Table of contents Preface $attrs example: $listen...
1. Triangle Border settings Code: width: 300px; h...
1. Enter start in the menu bar and click startup ...
A simple example of how to use the three methods ...
Web design is an emerging marginal industry that c...
When designing table structures, numeric types ar...
Suppose there is a table: reward (reward table), ...