oracle nvl2
时间: 2023-10-17 14:14:34 浏览: 76
`NVL2` is a function in Oracle that allows you to check if a value is null or not and return a different value based on that check.
The syntax for `NVL2` is as follows:
```
NVL2(expression1, expression2, expression3)
```
Here:
- `expression1` is the expression that you want to check for null.
- `expression2` is the value that you want to return if `expression1` is not null.
- `expression3` is the value that you want to return if `expression1` is null.
So, if `expression1` is not null, `NVL2` will return `expression2`. Otherwise, it will return `expression3`.
For example, the following query will return the value "Yes" if the `department_name` column is not null for a given row, otherwise it will return "No":
```
SELECT NVL2(department_name, 'Yes', 'No') AS has_department
FROM employees;
```
阅读全文