Updated on 2022-02-22 GMT+08:00

Relational Operators

All data types can be compared by using relational operators and the result is returned as a BOOLEAN value.

Relationship operators are binary operators. Two compared data types must be of the same type or they must support implicit conversion.

Table 1 lists the relational operators provided by DLI.

Table 1 Relational operators

Operator

Result Type

Description

A = B

BOOLEAN

If A is equal to B, then TRUE is returned. Otherwise, FALSE is returned. This operator is used for value assignment.

A == B

BOOLEAN

If A is equal to B, then TRUE is returned. Otherwise, FALSE is returned. This operator cannot be used for value assignment.

A <=> B

BOOLEAN

If A is equal to B, then TRUE is returned. Otherwise, FALSE is returned. If A and B are NULL, then TRUE is returned. If A or B is NULL, then FALSE is returned.

A <> B

BOOLEAN

If A is not equal to B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned. This operator follows the standard SQL syntax.

A != B

BOOLEAN

This operator is the same as the <> logical operator. It follows the SQL Server syntax.

A < B

BOOLEAN

If A is less than B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A <= B

BOOLEAN

If A is less than or equal to B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A > B

BOOLEAN

If A is greater than B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A >= B

BOOLEAN

If A is greater than or equal to B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A BETWEEN B AND C

BOOLEAN

If A is greater than or equal to B and less than or equal to C, then TRUE is returned. Otherwise, FALSE is returned. If A, B, or C is NULL, then NULL is returned.

A NOT BETWEEN B AND C

BOOLEAN

If A is less than B or greater than C, TRUE is returned; otherwise, FALSE is returned. If A, B, or C is NULL, then NULL is returned.

A IS NULL

BOOLEAN

If A is NULL, then TRUE is returned. Otherwise, FALSE is returned.

A IS NOT NULL

BOOLEAN

If A is not NULL, then TRUE is returned. Otherwise, FALSE is returned.

A LIKE B

BOOLEAN

If A matches B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A NOT LIKE B

BOOLEAN

If A does not match B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A RLIKE B

BOOLEAN

This operator is used for the LIKE operation of JAVA. If A or its substring matches B, then TRUE is returned. Otherwise, FALSE is returned. If A or B is NULL, then NULL is returned.

A REGEXP B

BOOLEAN

The result is the same as A RLIKE B.