小智 18
NVL检查第一个参数是否为null并返回第二个参数:
select nvl(null, 'arg2') from dual
Run Code Online (Sandbox Code Playgroud)
在这个例子中结果将是:arg2;
select nvl('arg1', 'arg2') from dual
Run Code Online (Sandbox Code Playgroud)
在这一个:arg1;
NVL2具有不同的逻辑.如果第一个参数不为null,则NVL2返回第二个参数,但在其他情况下,它将返回第三个参数:
select nvl2('arg1', 'arg2', 'arg3') from dual
Run Code Online (Sandbox Code Playgroud)
结果:arg2
select nvl2(null, 'arg2', 'arg3') from dual
Run Code Online (Sandbox Code Playgroud)
结果:arg3