浅谈mysql可有类似oracle的nvl的函数
2017-02-28来源:

要用ifnull,而不是isnull

isnull是判断是否为null,返回值是1表示null或者0表示不为空

ifnull等同于oracle的nvl,用法如下

mysql> select ifnull(1,10);

+--------------+

| ifnull(1,10) |

+--------------+

| 1 |

+--------------+

1 row in set (0.00 sec)

mysql> select ifnull(null,10);

+-----------------+

| ifnull(null,10) |

+-----------------+

| 10 |

+-----------------+

1 row in set (0.00 sec)

isnull的用法如下

mysql> select isnull(null);

+--------------+

| isnull(null) |

+--------------+

| 1 |

+--------------+

1 row in set (0.00 sec)

mysql> select isnull(1);

+-----------+

| isnull(1) |

+-----------+

| 0 |

+-----------+

1 row in set (0.00 sec)

推荐信息
Baidu
map