Previous Topic: Use Expressions and FunctionsNext Topic: Introduction to Functions


Expressions

An SQL expression is a series of operands related by arithmetic or character string operators that yields a value that can be used in other SQL clauses as an operand.

Valid operands for expressions are column names, host variables, literals, functions, and other expressions enclosed by parentheses. Valid operators for numeric expressions are (+, -, /, *) while character expressions have only the concatenation operator (||). If a value in an expression is NULL the expression value will be NULL. Numeric and character operands cannot be mixed in expressions. All operands must match the expected data type of the resulting value: numeric or character. Date, time, and timestamp data types are not supported in expressions. Like REXX the conventional rules of operator precedence and parenthetical evaluation order are applied.

The following are some examples of expressions:

Add 1 to an integer column value:

“UPDATE  TBL1 SET TOTAL_TIMES = TOTAL_TIMES + 1”

Use a function, literal, and character columns to produce a 'LAST NAME, FIRST NAME' value into a host variable:

“SELECT   TRIM(LAST_NAME) || ', ' || FIRST_NAME  INTO :NAME”