Background documentationComparison Predicate (comparison_predicate) Locate this document in the navigation structure

 

A comparison predicate (comparison_predicate) is a predicate that specifies a comparison between two values or lists of values.

Structure

Syntax Syntax

  1. <comparison_predicate> ::=
      <expression> <comp_op> <expression>
    | <expression> <comp_op> <subquery>
    | <expression_list> <equal_or_not> (<expression_list>)
    | <expression_list> <equal_or_not> <subquery>
End of the code.

The following operators are available for comparing two values:

Syntax Syntax

  1. <comp_op> ::=
      <
    | >
    | <>
    | !=
    | =
    | <=
    | >=
    | ~= <!  for computers with ASCII code  !>
    | ~< <!  for computers with ASCII code  !>
    | ~> <!  for computers with ASCII code  !>
End of the code.

Two value lists can only be compared with the following operators:

Syntax Syntax

  1. <equal_or_not> ::=
      <>
    | =
    | ~= <!  for computers with ASCII code  !>
End of the code.
Explanation

The subquery must supply a result table that contains the same number of columns as the number of values on the left of the operator. The result table may contain no more than one row.

The list of values (expression_list) specified to the right of the equal_or_not operator must contain the same number of values as specified in the value list in front of the equal_or_not operator.

The JOIN predicate is a special case.

Comparing Two Values

Let x be the result of the first expression and y the result of the second expression or of the subquery.

  • The values x and y must be comparable with one another.

  • Numbers are compared to one another according to their algebraic values.

  • Character strings are compared character by character.

    Any blanks (code attribute ASCII, UNICODE) or binary zeros (code attribute BYTE) at the end of one or both of the character strings are removed.

    If the character strings have the different code attributes ASCII and UNICODE, the character string with the code attribute ASCII is implicitly converted into a character string with the code attribute UNICODE. Two character strings are identical if they have the same characters in all positions.

    The relationship between two character strings that are not identical is defined by the first character that differs in a comparison from left to right. This comparison is performed in accordance with the code attribute selected for this column (ASCII, UNICODE, or BYTE).

  • If x or y are NULL values, or if the result of the subquery is empty, (x <comp_op> y) is not defined.

Comparing Two Value Lists

If a value list (expression_list) is specified on the left of the comparison operator equal_or_not, let x be the value list that comprises the results of the values x1, x2, ..., xn in this list. Let y be the result of the subquery or the result of the second value list. A value list y consists of the results of the values y1, y2, ..., yn.

  • A value xm must be comparable with the associated value ym.

  • x=y is true if for xm=ym for all m=1, ..., n.

  • x<>y is true if at least xm<>ym for at least one m.

  • (x <equal_or_not> y) is undefined if there is no m for which (xm <equal_or_not> ym) is false and there is at least one m for which (xm <equal_or_not> ym) is undefined.

  • If one xm or one ym is a NULL value, or if the result of the subquery is empty, (x <equal_or_not> y) is undefined.