A BETWEEN predicate compares a value with a range of values.
between-predicate =
--> value-expr -+--------+-> BETWEEN -+----------------+-+
+-> NOT -+ +-> ASYMMETRIC --+ |
+-> SYMMETRIC ---+ |
+-------------------------------------------------------+
+-> value-expr AND value-expr --------------------------->
See the Value_Expressions HELP topic for details on value
expressions.
ASYMMETRIC is the default.
The BETWEEN predicate is a simpler way of representing conditions
that can be represented using other conditional operators:
value1 BETWEEN value2 AND value3
Using the BETWEEN predicate is the same as using the following
complex predicate:
value1 >= value2
AND
value1 <= value3
ASYMMETRIC
By default, the BETWEEN predicate depends on the ordering of the
values. i.e. the first value expression needed to be less than
or equal to the second value expression and was evaluated as
equivalent to: V0
following example.
SQL> select a from t where a between asymmetric 2 and 4;
A
2
3
4
3 rows selected
The following query returns zero matches because the value
expressions are out of order.
SQL> select a from t where a between asymmetric 4 and 2;
0 rows selected
SYMMETRIC
This alternate format for BETWEEN allows simpler comparision of
unordered value expressions, as can be seen in these examples
which return the same results. This comparision is equivalent to:
(V0
For example:
SQL> select a from t where a between symmetric 2 and 4;
A
2
3
4
3 rows selected
SQL> select a from t where a between symmetric 4 and 2;
A
2
3
4
3 rows selected
Note that NOT BETWEEN operation also changes when using SYMMETRIC
This first query using ASYMMETRIC returns all values not in the
specified range.
SQL> select a from t where a not between asymmetric 2 and 4;
A
1
5
2 rows selected
In this next query the range values is out of order and the
BETWEEN predicate returns an empty set of matches, and therefore
NOT BETWEEN returns all rows in the example table.
SQL> select a from t where a not between asymmetric 4 and 2;
A
1
2
3
4
5
5 rows selected
Contrast this to SYMMETRIC which returns the same set of values
for either ordering of values:
SQL> select a from t where a not between symmetric 2 and 4;
A
1
5
2 rows selected
SQL> select a from t where a not between symmetric 4 and 2;
A
1
5
2 rows selected