Oracle 中的 NVL 和 NVL2 函数是什么?它们有何不同?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36936245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:13:49  来源:igfitidea点击:

What are the NVL and the NVL2 functions in Oracle? How do they differ?

sqloracle

提问by Salman Lone

I am looking for the detail answer with simple examples of these functions.

我正在寻找这些功能的简单示例的详细答案。

回答by vssk

NVLchecks if first argument is null and returns second argument:

NVL检查第一个参数是否为空并返回第二个参数:

select nvl(null, 'arg2') from dual

in this example result will be: arg2;

在这个例子中,结果将是:arg2;

select nvl('arg1', 'arg2') from dual

and in this one: arg1;

在这个:arg1;

NVL2has different logic. If first argument is not null then NVL2 returns second argument, but in other case it will return third argument:

NVL2有不同的逻辑。如果第一个参数不为空,则 NVL2 返回第二个参数,但在其他情况下它将返回第三个参数:

select nvl2('arg1', 'arg2', 'arg3') from dual

Result: arg2

结果:arg2

select nvl2(null, 'arg2', 'arg3') from dual

Result: arg3

结果:arg3