content_image/766489.jpg content_image/766484.jpg
• IFNULL( expr1 , expr2 ) 

If expr1  is not NULL , IFNULL()  returns expr1 ; otherwise it returns expr2 . 

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 return type of IFNULL( expr1 , expr2 )  is the more “general”  of the two expressions, in the order STRING , REAL , or INTEGER . Consider the case of a table based on expressions or where MySQL must internally store a value returned by IFNULL()  in a temporary table: 

mysql> CREATE TABLE tmp SELECT IFNULL(1,’test’) AS test; mysql> DESCRIBE tmp; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | test | varbinary(4) | NO | | | | +-------+--------------+------+-----+---------+-------+ 

In this example, the type of the test  column is VARBINARY(4)  (a string type). 

• NULLIF( expr1 , expr2 ) 

Returns NULL  if expr1  = expr2  is true, otherwise returns expr1 . This is the same as CASE WHEN expr1  = expr2  THEN NULL ELSE expr1  END . 

## 12.6 Numeric Functions and Operators 

The return value has the same type as the first argument. 

mysql> SELECT NULLIF(1,1); -> NULL mysql> SELECT NULLIF(1,2); -> 1 

<img src='content_image/766489.jpg'>

## Note 

MySQL evaluates expr1  twice if the arguments are not equal. 

<img src='content_image/766484.jpg'>

