Ifnull (expr1, expr2)
If expr1 is not null, the returned value of ifnull () is expr1;
Otherwise, the returned value is expr2. The returned value of ifnull () is a number or string, depending on the context in which it is used.
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'
The default result value of ifnull (expr1, expr2) is one of the two expressions that is more "common", in the order of string, real, or
Integer. Assume that an expression-based table or MySQL must store the returned value of ifnull () in a temporary table in internal memory:
Create Table TMP select ifnull (1, 'test') as test;
In this example, the test column type is Char (4 ).
Nullif (expr1, expr2)
If expr1
= Expr2 is true, then the return value is null, otherwise the return value is expr1. This is the same as case when expr1 = expr2
Then null else expr1 end is the same.
Mysql> select
Nullif (1, 1 );
-> Null
Mysql> select nullif (1, 2 );
-> 1