如何找出oracle数字的位数 [英] How to find out the number of digits of an oracle number
问题描述
我在 oracle 中有一个看起来像这样的表:
I have a table in oracle that looks like this:
name | type | nullable
------------------------------------------
person_name | varchar(20) | yes
weight_coeficient | number | yes
...
我怎样才能算出weight_coeficient 的值有多少位?例如:
How can I figure out how many digits a value of weight_coeficient has ? For example:
3.0123456789
有 11 位数字(精度 = 11) 和小数点后 10 位数字 (比例 = 10)
3.0123456789
has 11 digits (precision = 11) and 10 digits after the decimal (scale = 10)
是否有执行此操作的 sql 命令/函数,例如返回 11 的 GetPrecision( select.. )
?
Is there any sql command/function that does that, something like GetPrecision( select.. )
that returns 11 ?
另请注意,表的定义未指定比例和精度.所以据我所知,最大精度适用于所有数字.所以我对找出定义的精度(= 48)不感兴趣,而是对表中特定值的精度感兴趣.是否可以仅使用 oracle 命令?
Note also that the definition of the table does not specify scale and precision. So as far as I know the maximum precision is applied for all the numbers. So I'm not interested in finding out the precision (= 48) of the definition, but the precision of a specific value in the table. Is that possible just using oracle commands ?
提前谢谢你,
JP
Thank you in advance,
JP
推荐答案
怎么样....
SELECT LENGTH(TRANSLATE(TO_CHAR(3.0123456789),'1234567890.-','1234567890'))
FROM dual
翻译只是删除非数字字符.-
The translate simply removes the non numeric characters .-
这篇关于如何找出oracle数字的位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!