Logical Operators
Logical data is data that has been converted to a logical format for use in logical operations. There are three values that logical data can have: TRUE, FALSE, or NULL. Three types of data—numeric data, string data, and the null value—can function as logical data.
- Numeric DataThe numeric value 0 (zero), is false; all other numeric values are true. The following are examples of the logical equivalent of numeric data:
- 1 = TRUE
- 25 = TRUE
- 0 = FALSE
- String Data
An empty character string is false; all other string data is true. The following are examples of the logical equivalent of string data:
- "example" = TRUE
- "var1" = TRUE
- "" = FALSE
- Null Value
The null value is neither true nor false. It represents data whose value is undefined.
Logical operators perform tests on logical expressions. Logical expressions that evaluate to zero or an empty string are false. Logical expressions that evaluate to null are null. Expressions that evaluate to any other value are true.
There are three logical operators in InfoSphere® DataStage® BASIC:
- AND (or the equivalent &)
- OR (or the equivalent |)
- NOT
The operands of logical operators are considered to be logical data types. The following sections show the results of each operator in detail.
The following table displays how values for X and Y affect the value of the expression X AND Y. For example, the first row shows that if X is true and Y is true, then the value of X AND Y is true.
X | Y | X AND Y |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | NULL | NULL |
TRUE | FALSE | FALSE |
NULL | TRUE | NULL |
NULL | NULL | NULL |
NULL | FALSE | FALSE |
FALSE | TRUE | FALSE |
FALSE | NULL | FALSE |
FALSE | FALSE | FALSE |
The following table displays how values for X and Y affect the value of the expression X OR Y. For example, the third row shows that if X is true and Y is false, then the value of X OR Y is true.
X | Y | X OR Y |
---|---|---|
TRUE | TRUE | TRUE |
TRUE | NULL | TRUE |
TRUE | FALSE | TRUE |
NULL | TRUE | TRUE |
NULL | NULL | NULL |
NULL | FALSE | NULL |
FALSE | TRUE | TRUE |
FALSE | NULL | NULL |
FALSE | FALSE | FALSE |
The NOT operator is slightly different from the preceding operators since NOT effectively reverses the value of the expression, that is, it inverts the logical value. Since NULL is an unknown logical value, the inverse is also NULL.
- NOT TRUE = FALSE
- NOT NULL = NULL
- NOT FALSE = TRUE
Arithmetic and relational operations take precedence over logical operations. InfoSphere DataStage logical operations are evaluated from left to right (i.e., AND statements do not take precedence over OR statements).