This Oracle tutorial explains how to use the Oracle/PLSQL COALESCE function with syntax and examples.
The Oracle/PLSQL COALESCE function returns the first non-null expression in the list. If all expressions evaluate to null, then the COALESCE function will return null.
The syntax for the COALESCE function in Oracle/PLSQL is:
The expressions to test for non-null values. The expressions must all be the same datatype.
The COALESCE function returns returns any datatype such as a string, numeric, date, etc. (BUT all expressions must be the same datatype in the COALESCE function.) If all expressions are not the same datatype, an >ORA-00932 error will be returned.
The COALESCE function can be used in the following versions of Oracle/PLSQL:
The COALESCE function can be used in Oracle/PLSQL.
You could use the coalesce function in a SQL statement as follows:
The above COALESCE function is equivalent to the following IF-THEN-ELSE statement:
The COALESCE function will compare each value, one by one.