What is the usage of the oracle NVL2 function?
The Oracle NVL2 function is a conditional expression function used to choose between two values. It takes three parameters: expression1, expression2, and expression3.
Return the value of expression2 if the value of expression1 is not NULL; otherwise, return the value of expression3.
The syntax is as follows: NVL2(expression1, expression2, expression3)
Among them:
- Expression that needs to check for NULL.
- If expression1 is not NULL, return its value.
- expression3: The returned value if expression1 is NULL.
SELECT NVL2(NULL, ‘A’, ‘B’) FROM dual; -> The NVL2 function is used to return ‘A’ if the first argument is not null, otherwise it returns ‘B’.
Result:
B