oracle decode
时间: 2023-09-22 16:14:12 浏览: 49
The Oracle DECODE function is a conditional statement that evaluates a set of expressions and returns a value based on the first expression that is true. It can be used to perform simple if-then-else logic in SQL queries.
The syntax for the DECODE function is:
DECODE(expr, search1, result1, search2, result2, ..., default)
- expr: The expression to be evaluated.
- search1, search2, ...: The expressions to be compared against expr.
- result1, result2, ...: The value to be returned if the corresponding search expression matches expr.
- default: The value to be returned if no search expression matches expr.
For example, the following query uses DECODE to return 'Yes' if the quantity is greater than 10, 'No' if the quantity is less than 10, and 'Equal' if the quantity is exactly 10:
SELECT DECODE(quantity, 10, 'Equal', quantity > 10, 'Yes', 'No') AS result
FROM orders;
This will return a result set with a column named "result" that contains 'Yes', 'No', or 'Equal' for each row.