📜  Oracle BETWEEN(1)

📅  最后修改于: 2023-12-03 14:44:55.349000             🧑  作者: Mango

Oracle BETWEEN

BETWEEN is a comparison operator that allows you to specify a range of values within which a column's value must fall. It is usually used in WHERE clauses to filter rows.

Syntax
expression BETWEEN value1 AND value2
  • expression: any valid expression that can be evaluated to a value.
  • value1: the starting value of the range.
  • value2: the ending value of the range.
Example

Suppose you have a table employees:

| id | name | age | |----|--------|-----| | 1 | Alice | 25 | | 2 | Bob | 30 | | 3 | Charlie| 35 | | 4 | Dave | 40 |

If you want to select all employees whose age is between 30 and 35, you can use the following SQL statement:

SELECT * FROM employees WHERE age BETWEEN 30 AND 35;

The result would be:

| id | name | age | |----|--------|-----| | 2 | Bob | 30 | | 3 | Charlie| 35 |

Note that the range is inclusive - both 30 and 35 are included in the result. If you want to exclude one end of the range, you can use the comparison operators < and > instead.

Conclusion

BETWEEN is a powerful operator that allows you to easily filter rows based on a range of values. It's a commonly used feature in SQL and can help you write more efficient and effective queries.