Oracle BETWEEN Operator πΒΆ
Prerequisites: WHERE Clause
Mentor's Note:
BETWEENis the tool for finding ranges. It is inclusive, meaning it includes the starting and ending values you specify. π‘
π The Scenario: The Budget Check π°ΒΆ
- Goal: Find all products that cost between βΉ100 and βΉ500.
- Action: You use
BETWEEN 100 AND 500. (This includes exactly βΉ100 and βΉ500!).
π» 1. Syntax & ExamplesΒΆ
Example: Salary RangeΒΆ
Example: Date Range (Very Common!) π ΒΆ
SELECT first_name, hire_date
FROM employees
WHERE hire_date BETWEEN '01-JAN-2020' AND '31-DEC-2020';
ποΈ Architect's Note: Date Precision π‘οΈΒΆ
Be careful when using BETWEEN with Oracle DATE types that include Time.
- '31-DEC-2020' is actually '31-DEC-2020 00:00:00'.
- A record from 10 PM on that day will NOT be included!
- Architect's Tip: Use TRUNC(hire_date) or explicit time comparisons for 100% accuracy.