A
numeric
expression resolves to a number, and you specify such an expression in
various situations; for example, on the right side of an assignment statement.
A numeric expression may be composed of any of these:
- A numeric operand, which is one of these:
- A variable that contains a number. The item may be preceded with a sign.
- A numeric literal, which may begin with a sign, but always has a series
of digits and may include a single decimal point.
- A function invocation that returns a number.
The type of a numeric literal is implied by the value of that literal:
- An integer of 4 digits or less is of type SMALLINT
- An integer of 5 to 8 digits is of type INT
- An integer of 9 to 18 digits is of type BIGINT
- A number that includes a decimal point is of type NUM
- A numeric operand, followed by a numeric operator, followed by a second
numeric operand.
- A more complex expression formed by using a numeric operator to combine
a pair of more elementary expressions.
You may use paired parentheses in a numeric expression to change the order
of evaluation or to clarify your meaning.
In reviewing the examples that follow, assume that intValue1 equals 1,
intValue2 equals 2, and so on, and that each value has no decimal places:
/* == -8, with the parentheses overriding
the usual precedence of * and + */
intValue2 * (intValue1 - 5)
/* == -2, with a unary minus as the last operator */
intValue2 + -4
/* == 1.4, if the expression is assigned to an
item with at least one decimal place. */
intValue7 / intValue5
/* == 2, which is a remainder
expressed as an integer value */
intValue7 % intValue5
For an example that shows the effect of parentheses on the use of a plus
(+) sign, see Expressions.
A numeric expression may give an unexpected result if an
intermediate, calculated value requires more than 128 bits.