Oracle NVL Function: Replace NULL Values in SQL
The NVL function in Oracle SQL is used to replace NULL values with a specified value. The syntax is as follows:
If expr1 is not null, return expr1; otherwise, return expr2.
If expr1 is the expression to be checked, it will return expr2 if its value is NULL, otherwise it will return the value of expr1.
For example, let’s say we have a table called Employee with a field Salary that may contain NULL values. We can use the NVL function to replace NULL values with 0, as shown below:
SELECT NVL(Salary, 0) AS NewSalary
FROM Employee;
In the example above, return 0 if the value of the Salary field is NULL, otherwise return the actual value of the Salary field.