NVL(表达式1,表达式2)
如果表达式1为空值,NVL返回值为表达式2的值,否则返回表达式1的值。 该函数的目的是把一个空值(null)转换成一个实际的值。其表达式的值可以是数字型、字符型和日期型。但是表达式1和表达式2的数据类型必须为同一个类型。
select * from reglike; select nvl(name,'000') name from reglike;
![](https://images2017.cnblogs.com/blog/890017/201711/890017-20171107164923638-1795160190.png)
![](https://images2017.cnblogs.com/blog/890017/201711/890017-20171107164924559-1311324286.png)
二、 NVL2(表达式1,表达式2,表达式3)
如果表达式1为空,返回值为表达式3的值。如果表达式1不为空,返回值为表达式2的值。
select * from reglike; select nvl2(name,'000','111') name from reglike;
![](https://images2017.cnblogs.com/blog/890017/201711/890017-20171107164923638-1795160190.png)
![](https://images2017.cnblogs.com/blog/890017/201711/890017-20171107164924825-755739102.png)