Section E.4. Operators


E.4. Operators

Operators are used to compose identifiers and literals into larger expressions. Operators can be logical operators , arithmetic operators, or comparison operators.

E.4.1. Logical Operators

The logical operators are NOT, AND, and OR. These are in precedence order. These have the usual Boolean logic semantics. If a logical operator is applied to header fields or properties whose value is NULL, then the following rules apply:

  • ANDing a NULL value with a FALSE value evaluates to FALSE; ANDing a NULL with a trUE or NULL value evaluates to a NULL (or unknown) value.

  • ORing a NULL value with a trUE value evaluates to trUE; ORing a NULL with a FALSE or a NULL value evaluates to a NULL (or unknown) value.

  • Applying NOT to a NULL value evaluates to a NULL (or unknown) value.

E.4.2. Arithmetic Operators

The arithmetic operators, in precedence order, are + and - (unary); * and /; and + and - (binary). These have the usual arithmetic semantics. Any arithmetic operator that is applied to one or more NULL values evaluates to a NULL value.

E.4.3. Comparison Operators

The comparison operators can be loosely grouped into equality comparisons and range comparisons. The basic equality comparison operators, in precedence order, are =, >, >=, <, <=, and <>. These binary operators have to be applied to two values of the same type, else the expression will always evaluate to FALSE. If either value is NULL, then the result of the comparison is NULL. There are also the equality operators IS NULL and IS NOT NULL to compare a value to NULL. An equality operator can also be used to check for the presence of a header or property. For example:

 timezone IS NOT NULL AND country = 'United Kingdom' 

There are also set and range comparison operators. The BETWEEN operator can be used to check the range of numeric values. For example:

 userid BETWEEN 00000000 AND 09999999 currRate NOT BETWEEN 0.0 AND 0.9999

The IN operator can be used to perform membership operations on string values:

 JMSType IN ('msgAck', 'queryAck', 'updateAck') JMSType NOT IN ('msgBroadcast', 'synchMessage')

There is also a string comparison operator, LIKE, that allows for wildcard matching on string values. A pattern is used for the right side of the LIKE operator. The pattern consists of a valid string literal where the underscore character, _, matches against any single character, while the % character matches any sequence of zero or more characters. For example:

 JMSType like '%Ack' label not like 'Step _'

The _ and % characters can be used in these string comparison operators if they are escaped by \. For example:

 slogan LIKE '99 44/100\% pure' 



Java Enterprise in a Nutshell
Java Enterprise in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596101422
EAN: 2147483647
Year: 2004
Pages: 269

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net