7.25.2 Data types of the results of arithmetic operations
The data type of the result of an arithmetic operation is determined by the data types of the first and second operands. The following table shows the relationship between the data types of the operands and the data type of the result of the operation.
No. |
Data type of the first operand |
Data type of the second operand |
Data type of the result of the operation |
---|---|---|---|
1 |
SMALLINT |
SMALLINT |
INTEGER |
2 |
INTEGER |
||
3 |
DECIMAL |
DECIMAL |
|
4 |
DOUBLE PRECISION |
DOUBLE PRECISION |
|
5 |
INTEGER |
SMALLINT |
INTEGER |
6 |
INTEGER |
||
7 |
DECIMAL |
DECIMAL |
|
8 |
DOUBLE PRECISION |
DOUBLE PRECISION |
|
9 |
DECIMAL |
SMALLINT |
DECIMAL |
10 |
INTEGER |
||
11 |
DECIMAL |
||
12 |
DOUBLE PRECISION |
DOUBLE PRECISION |
|
13 |
DOUBLE PRECISION |
SMALLINT |
DOUBLE PRECISION |
14 |
INTEGER |
||
15 |
DECIMAL |
||
16 |
DOUBLE PRECISION |
If the data type of the result of the operation is DECIMAL, the precision and scaling will be as follows:
Let the first operand be DECIMAL(p1,s1), the second operand be DECIMAL(p2,s2), and the result of the operation be DECIMAL(p,s).
-
For addition and subtraction
p = 1 + MAX(p1 - s1, p2 - s2) + s
s = MAX(s1, s2)
If the result of calculating p is 39 or greater, p = 38.
-
For multiplication
p = p1 + p2
s = s1 + s2
If the result of calculating p is 39 or greater, p = 38 and s = MAX(s1, s2).
-
For division
p = 38
s = MAX{0#, 38 - (p1-s1 + s2)}
- #
-
If the value specified for the adb_sql_prep_dec_div_rs_prior operand in the server definition or client definition is FRACTIONAL_PART, this value is replaced with s1.
If the data type is INTEGER, change the data type to DECIMAL(20,0) during calculation. If the data type is SMALLINT, change the data type to DECIMAL(10,0) during calculation.