Summary:
See also: Variables, Data Types, Literals, Constants.
An Expression is a sequence of operands, operators, and parentheses that the runtime system can evaluate as a single value.
Expressions can include the following components:
Expressions in SQL statements are evaluated by the database server, not by the runtime system. The set of operators that can appear in SQL expressions resembles the set of BDL operators, but they are not identical. A program can include SQL operators, but these are restricted to SQL statements. Similarly, most SQL operands are not valid in BDL expressions. The SQL identifiers of databases, tables, or columns can appear in a LIKE clause or field name in BDL statements, provided that these SQL identifiers comply with the naming rules of BDL. Here are some examples of SQL operands and operators that cannot appear in other BDL expressions:
Conversely, you cannot include BDL specific operators in SQL expressions, as for example:
You can use parentheses as you would in algebra to override the default order of precedence of operators. In mathematics, this use of parentheses represents the "associative" operator. It is, however, a convention in computer languages to regard this use of parentheses as delimiters rather than as operators. (Do not confuse this use of parentheses to specify operator precedence with the use of parentheses to enclose arguments in function calls or to delimit other lists.)
In the following example, the variable y is assigned the value of 2:
LET y = 15 MOD 3 + 2
In the next example, however, y is assigned the value of 0 because the parentheses change the sequence of operations:
LET y = 15 MOD (3 + 2)
A Boolean expression is one that evaluates to an INTEGER value that can be TRUE, FALSE and in some cases, NULL.
If an expression that returns NULL is the operand of the IS NULL operator, the value of the Boolean expression is TRUE:01
MAIN02
DEFINE b BOOLEAN03
LET b = ( TRUE AND FALSE )04
IF b THEN05
DISPLAY "TRUE"06
END IF07
END MAIN
If you include a Boolean expression in a context where the runtime system expects a number, the expression is evaluated, and is then converted to an integer by the rules: TRUE = 1 and FALSE = 0:01
MAIN02
DEFINE r INTEGER03
LET r = NULL04
IF r IS NULL THEN05
DISPLAY "TRUE"06
END IF07
END MAIN
The Boolean expression evaluates to TRUE if the value is a non-zero real number or any of the following items:
A Boolean expression evaluates to NULL if the value is NULL and the expression does not appear in any of the following contexts:
Boolean expressions in CASE, IF, or WHILE statements return FALSE if any element of the comparison is NULL, except for operands of the IS NULL and the IS NOT NULL operator. See Boolean Operators for more information about individual Boolean operators and Boolean expressions.
01
MAIN02
DEFINE r, c INTEGER03
LET c = 403
LET r = ( FALSE!=FALSE ) AND ( c=2 OR c=4 )04
IF ( r AND canReadFile("config.txt") ) THEN05
DISPLAY "OK"06
END IF07
END MAIN
An Integer expression is one that evaluates to a whole number.
The operands must be one of:
If an element of an integer expression is NULL, the expression is evaluated to NULL.
01
MAIN02
DEFINE r, c INTEGER03
LET c = 404
LET r = c * ( 2 + c MOD 4 ) / getRowCount("customers")05
END MAIN
A Number expression is one that evaluates to a number data type.
The operands must be one of:
If an element of a number expression is NULL, the expression is evaluated to NULL.
01
MAIN02
DEFINE r, c DECIMAL(10,2)03
LET c = 456.2204
LET r = c * 2 + ( c / 4.55 )05
END MAIN
A String expression is one that includes at least one character string value and that evaluates to the STRING data type.
At least one of the operands must be one of:
If an element of an integer expression is NULL, the expression is evaluated to NULL.
An empty string ("") is equivalent to NULL.
01
MAIN02
DEFINE r, c VARCHAR(100)03
LET c = "abcdef"04
LET r = c[1,3] || ": " || TODAY USING "YYYY-MM-DD" || " " || length(c)05
END MAIN
A Date expression is one that evaluates to a DATE data type.
The operands must be one of:
If an element of an integer expression is NULL, the expression is evaluated to NULL.
01
MAIN02
DEFINE r, c DATE03
LET c = TODAY + 404
LET r = ( c - 2 )05
END MAIN
A Datetime expression is one that evaluates to a DATETIME data type.
The operands must be one of:
If an element of an integer expression is NULL, the expression is evaluated to NULL.
01
MAIN02
DEFINE r, c DATETIME YEAR TO SECOND03
LET c = CURRENT YEAR TO SECOND04
LET r = c + INTERVAL( 234-02 ) YEAR TO MONTH05
END MAIN
An Interval expression is one that evaluates to a INTERVAL data type.
The operands must be one of:
If an element of an integer expression is NULL, the expression is evaluated to NULL.
01
MAIN02
DEFINE r, c INTERVAL HOUR TO MINUTE03
LET c = "12:45"04
LET r = c + ( DATETIME(14:02) HOUR TO MINUTE - DATETIME(10:43) HOUR TO MINUTE )05
END MAIN