1. COALESCE 函数
coalesce(a, b, c, ...)
返回参数里第一个不为空的值。
SELECT ename, coalesce(comm, 0) as comm FROM emp;
示例结果( Jane的comm为空值 ):
+-------+------+
| ename | comm |
+-------+------+
| John | 500 |
| Jane | 0 |
+-------+------+
2. NVL 函数
NVL(x, y)
如果 x 不为 NULL,就返回 x,否则返回 y。
SELECT ename, nvl(comm, 0) as comm FROM emp;
示例结果( Jane的comm为空值 ):
+-------+------+
| ename | comm |
+-------+------+
| John | 500 |
| Jane | 0 |
+-------+------+