Numeric Value Expressions
•
"Considerations for Numeric Value Expressions"
•
"Examples of Numeric Value Expressions"
The operands of a numeric value expression can be combined in specific ways with arithmetic
operators. In this syntax diagram, the data type of a term, factor, or numeric primary is numeric
.
numeric-expression is:
numeric-term
| numeric-expression + numeric-term
| numeric-expression - numeric-term
numeric-term is:
numeric-factor
| numeric-term * numeric-factor
| numeric-term / numeric-factor
numeric-factor is:
[+|-] numeric-primary
| [+|-] numeric-primary ** numeric-factor
numeric-primary is:
unsigned-numeric-literal
| column-reference
| numeric-type-host-variable
| dynamic parameter
| numeric-value-function
| aggregate-function
| sequence-function
| scalar-subquery
| CASE-expression
| CAST-expression
| (numeric-expression)
As shown in the preceding syntax diagram, numeric value expressions are built from operands
that can be:
•
Numeric literals
•
Column references with numeric values
•
Dynamic parameters
•
Numeric value functions
•
Aggregate functions, sequence functions, scalar subqueries, CASE expressions, or CAST
expressions that return numeric values
Considerations for Numeric Value Expressions
Order of Evaluation
1.
Expressions within parentheses
2.
Unary operators
3.
Exponentiation
4.
Multiplication and division
5.
Addition and subtraction
Operators at the same level are evaluated from left to right for all operators except exponentiation.
Exponentiation operators at the same level are evaluated from right to left. For example, X + Y
+ Z is evaluated as (X + Y) + Z, whereas X ** Y ** Z is evaluated as X ** (Y ** Z).
Additional Rules for Arithmetic Operations
Expressions
217