SQL Reference

Arithmetic Operations Supported

Overview

 supports addition, subtraction, multiplication, and division between any two numeric types. Division involving two integral types always results in an integral type.

Decimal Precision

These rules determine the precision p and scale s for the result of a specified expression that involves decimals d1 and d2, with precisions p1 and p2, and scales s1 and s2:

Operation

Precision

Scale

addition, subtraction

max(s1, s2) + max(p1-s1, p2-s2) + 1

max(s1, s2)

multiplication

p1 + p2

s1 + s2

division

See note.

max(6, s1 + p2 + 1)

For division, the resulting precision is the minimum necessary to hold the whole number portion of the result. If that portion does not exist because the absolute value of the result is less than one, the resulting precision is one greater than the scale. For other operations, the result might still have a lower precision (but the same scale) than specified by these rules when the result would otherwise have a leading insignificant zero.

If the resulting precision exceeds 31, the database decreases both precision and scale until the precision is 31, except in division where the minimal scale is always six. If the resulting precision still exceeds 31, the database truncates it to 31. The database returns an overflow error when the result exceeds the available integral portion of the result. When the database decreases the resulting scale, it truncates the excess fractional digits in the result.

Additional Supported Data Type Combinations

Addition

Text


Subtraction

Text


Multiplication

Text


Division

Text