In Oracle SQL, the NVL function is commonly used to handle null values. It returns the first non-null expression among its arguments. If the first expression is null, it returns the second expression. If both expressions are null, it returns null.
Here's the syntax:
NVL(expr1, expr2)
expr1: This is the expression to be evaluated. If it is null,NVLreturnsexpr2.expr2: This is the expression to return ifexpr1is null.
Example:
SELECT NVL(column_name, 'default_value') AS result FROM your_table;
This query selects the column_name from your_table. If column_name is null, it returns 'default_value'.
If you're using Oracle and want to return a null value if a condition is true, you can use the CASE expression:
SELECT CASE WHEN condition THEN NULL ELSE some_value END AS result FROM your_table;
This query returns
NULL if condition is true; otherwise, it returns some_value.
Tags:
Oracle