NVL AND NVL2 FUNCTION in ORACLE SQL

 NVL FUNCTION



In SQL Server, the equivalent function to Oracle's NVL is ISNULL. Here's an example of how to use it:


SELECT ISNULL(NULL, 'Hello World') AS result;


This will return the value "Hello World" as the result. If the first input parameter (NULL) had a non-null value, it would have been returned instead.

The ISNULL function can take any data type as input and returns the same data type as the first input parameter. If the first parameter is null, it returns the second parameter.



 NVL2  FUNCTION


SELECT NVL2('x', 'y', 'z') AS result FROM dual;



This will return the value "y" as the result because the first input parameter ('x') is not null. If the first input parameter was null, the function would return the third parameter ('z') instead.

The NVL2 function takes three input parameters. If the first parameter is not null, it returns the second parameter. If the first parameter is null, it returns the third parameter.


The result of this query will be:





This is because the first input parameter to the NVL2 function is the non-null value 'x', so the function returns the second input parameter ('y') as the result. If the first input parameter were null, the function would return the third input parameter ('z') instead.



Post a Comment

Previous Post Next Post