Comparison operators

更新时间:
复制 MD 格式

PolarDB for Oracle supports the following comparison operators for all valid data types. All comparison operators are binary operators that return boolean values.

OperatorDescriptionExample
<Less thansalary < 5000
>Greater thansalary > 5000
<=Less than or equal tosalary <= 5000
>=Greater than or equal tosalary >= 5000
=Equalstatus = 'active'
<>Not equalstatus <> 'inactive'
!=Not equalstatus != 'inactive'

Because comparison operators return boolean values, chaining them is not valid. For example, 1 < 2 < 3 is invalid — the second < would need to compare a boolean result with 3, which is not supported.

BETWEEN

The BETWEEN construct tests whether a value falls within an inclusive range:

  • a BETWEEN x AND y is equivalent to a >= x AND a <= y

  • a NOT BETWEEN x AND y is equivalent to a < x OR a > y

Both forms produce identical results. The first form is internally rewritten to the second before execution.

NULL comparisons

To test whether a value is NULL, use IS NULL or IS NOT NULL:

expression IS NULL
expression IS NOT NULL

Do not use expression = NULL. NULL represents an unknown value, so comparing it with = does not return true — it returns NULL. This behavior conforms to the SQL standard.

If your application relies on expression = NULL returning true, update it to use IS NULL instead.