6

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

3

3 Answers 3

22

NVL checks if first argument is null and returns second argument:

select nvl(null, 'arg2') from dual

in this example result will be: arg2;

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

and in this one: arg1;

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

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

Result: arg2

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

Result: arg3

1

Nvl(arg1,arg2) nvl is used for converting null values. In nvl if argument 1 is null then it returns argument 2 but argument 1 is not null it returns itself. In nvl2 (arg1,arg2,arg3) in nvl2 it converts any number into according to given number with null also . If arg 1 that's given number is null then it returns arg3 And on the other hand if it is not null it returns argument 2

0

Both the NVL(exp1, exp2) and NVL2(exp1, exp2, exp3) functions check the value exp1 to see if it is null.

With the NVL(exp1, exp2) function, if exp1 is not null, then the value of exp1 is returned; otherwise, the value of exp2 is returned, but case to the same data type as that of exp1.

With the NVL2(exp1, exp2, exp3) function, if exp1 is not null, then exp2 is returned; otherwise, the value of exp3 is returned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.