oracle COALESCE
时间: 2023-11-01 20:40:35 浏览: 80
Oracle COALESCE is a function that is used to return the first non-null expression in a list of expressions. The syntax for the COALESCE function is as follows:
COALESCE(expr1, expr2, ..., exprn)
The function takes a variable number of arguments, and returns the first argument that is not null. If all arguments are null, the function returns null.
For example, suppose we have a table called "employees" with columns "employee_id", "first_name", "last_name", and "middle_name". We can use the COALESCE function to return the first non-null name for each employee:
SELECT employee_id, COALESCE(first_name, middle_name, last_name) as name
FROM employees;
This will return a result set with two columns: "employee_id" and "name". The "name" column will contain the first non-null name for each employee, in the order specified by the COALESCE function.
阅读全文