Teradata 中的 DECIMAL 类型 [英] DECIMAL Types in Teradata
问题描述
谁能解释一下我在 Teradata 中得到的以下结果:
Can somebody please explain the following result I get in Teradata:
SELECT TYPE(CAST (2.3 AS DECIMAL(18,4)) * CAST (2.3 AS DECIMAL(18,4)) )
结果是:
DECIMAL(18,8)
我期待 DECIMAL(18,4)
I was expecting DECIMAL(18,4)
推荐答案
对于涉及小数的计算,每个 DBMS 都有自己的规则.
Every DBMS has it's own rules regarding calculations involving Decimals.
Teradata 的基本规则是:当您添加/减去/除以 DECIMAL 时,得到的小数精度是两个操作数中较大的一个,例如dec(10,2) + dec(10,4) = dec(xx,4)
Teradata's basic rules are: When you add/substract/divide DECIMALs the resulting fractional precision is the greater of both operands, e.g. dec(10,2) + dec(10,4) = dec(xx,4)
但是当你乘以小数位数时,例如dec(10,2) * dec(10,4) = dec(xx,6)
But when you multiply the fractional digits are added, e.g.dec(10,2) * dec(10,4) = dec(xx,6)
整体精度有更多规则(一些取决于 dbscontrol MAxDecimal 设置).
The overall precision has some more rules (some depending on the dbscontrol MAxDecimal setting).
然后是最重要的规则,人们往往会忘记:每次计算后,结果都会四舍五入到这个精度.
And then there's the most important rule, people tend to forget: After each calculation the result is rounded to this precision.
sel 2.0/3.00 * 100, 100*2.0/3.00;
*** Query completed. One row found. 2 columns returned.
*** Total elapsed time was 1 second.
((2.0/3.00)*100) ((100*2.0)/3.00)
----------------- -----------------
67.00 66.67
节食者
这篇关于Teradata 中的 DECIMAL 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!