SQL-J Language Reference
Page 114 of 121

Boolean expression

Boolean expressions are allowed in a number of places, most notably in WHERE clauses, but also in check constraints and VALUES expressions. Boolean expressions in check constraints have limitations not noted here; see CONSTRAINT clause for more information. Boolean expressions in a WHERE clause have a highly liberal syntax; see WHERE clause, for example.

A boolean expression can include a boolean operator or operators. These are listed in Table 1-10.

Table 1-10 SQL-J Boolean Operators 

Operator

Explanation and Example

Syntax

AND, OR, NOT

Evaluate any operand(s) that are boolean expressions

(orig_airport = 'SFO') OR
    (dest_airport = 'GRU')
    -- returns true

{
  Expression AND
    Expression |
  Expression OR
    Expression |
  NOT Expression

}

Comparisons

<, =, >, <=, >=, <> are applicable to all of the built-in types.

DATE'1998-02-26' <
    DATE'1998-03-01'
-- returns true

Expression
{
  < |
  = |
  > |
  <= |
  >= |
  <>
}
Expression

IS NULL, IS NOT NULL

Test whether the result of an expression is null or not.

WHERE MiddleName IS NULL

Expression IS [ NOT ]
  NULL

LIKE

Attempts to match a character expression to a character pattern, which is a character string that includes one or more wildcards.

% matches any number (zero or more) of characters in the corresponding position in first character expression.

_ matches one character in the corresponding position in the character expression.

Any other character matches only that character in the corresponding position in the character expression.

city.getName() LIKE 'Sant_'

CharacterExpression
  [ NOT ] LIKE
  CharacterExpression
  WithWildCard

BETWEEN

Tests whether the first operand is between the second and third operands. The second operand must be less than the third operand. Applicable only to types to which <= and >= can be applied.

WHERE booking_date BETWEEN
    DATE'1998-02-26' AND
    DATE'1998-03-01

Expression [ NOT ]
BETWEEN Expression
  AND Expression

IN

Operates on table subquery or list of values. Returns TRUE if the left expression's value is in the result of the table subquery or in the list of values. Table subquery can return multiple rows but must return a single column.

WHERE booking_date NOT IN
    (SELECT booking_date FROM
HotelBookings WHERE rooms_available = 0)

{
  Expression [ NOT ]
    IN
     TableSubquery |

  Expression [ NOT ]
    IN ( Expression
    [, Expression ]* )
}

EXISTS

Operates on a table subquery. Returns TRUE if the table subquery returns any rows, and FALSE if it returns no rows. Table subquery can return multiple columns (only if you use * to denote multiple columns) and rows.

WHERE EXISTS
  SELECT *
  FROM Flights
  WHERE dest_airport = 'SFO'
  AND orig_airport = 'GRU')

EXISTS TableSubquery

IS

Allows you to test whether a boolean expression returns TRUE, FALSE, or UNKNOWN.

For example, for the following expression:

c=3

it returns TRUE if c is 3, FALSE if c is any other value, and UNKNOWN if c is NULL.

Useful in constraints. See CONSTRAINT clause.

BooleanExpression IS
  [NOT]
{
  TRUE |
  FALSE |
  UNKNOWN
}

Quantified comparison

A quantified comparison is a comparison operator (<, =, >, <=, >=, <>) with ALL or ANY or SOME applied.

Operates on table subqueries, which can return multiple rows but must return a single column.

If ALL is used, the comparison must be true for all values returned by the table subquery. If ANY or SOME is used, the comparison must be true for at least one value of the table subquery. ANY and SOME are equivalent.

WHERE normal_rate < ALL (SELECT budget/550 FROM Groups)

Expression
  ComparisonOperator
  {
    ALL |
    ANY |
    SOME
  }

   TableSubquery


INSTANCEOF

Returns TRUE if the type of the Expression is an implementation or subtype of the JavaClassName type. If the Expression evaluates to NULL, the INSTANCEOF expression returns FALSE.

See INSTANCEOF Expression.

Expression INSTANCEOF
   JavaClassName