IFNULL

Description

If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. The default return type of IFNULL(expr1,expr2) is the more “general” of the two expressions, in the order STRING, REAL, or INTEGER.

Syntax

  1. > IFNULL(expr1,expr2)

Examples

  1. mysql> SELECT IFNULL(NULL,10);
  2. +------------------+
  3. | ifnull(null, 10) |
  4. +------------------+
  5. | 10 |
  6. +------------------+
  7. 1 row in set (0.00 sec)
  1. mysql> SELECT CAST(IFNULL(NULL, NULL) AS DECIMAL);
  2. +-----------------------------------------+
  3. | cast(ifnull(null, null) as decimal(10)) |
  4. +-----------------------------------------+
  5. | NULL |
  6. +-----------------------------------------+
  7. 1 row in set (0.01 sec)