Usage of the NVL() function in SQL statements.
In SQL, NVL() is a function that is used to replace the value of an expression or field with another specified value if the original value is NULL.
The syntax of the NVL() function is as follows:
IF expr1 IS NOT NULL THEN RETURN expr1 ELSE RETURN expr2
expr1 represents the expression or field to be checked, while expr2 represents the value to replace it with.
The NVL() function will return the value of expr2 if the value of expr1 is NULL. Otherwise, it will return the value of expr1.
Here is an example of the NVL() function:
Choose column1, but if column2 is null then display ‘Unknown’ and name it column2 from table1.
In the above example, if the value of column2 is NULL, the NVL() function will return the string ‘Unknown’. If the value of column2 is not NULL, the NVL() function will return the value of column2.