如何在Oracle PLSQL中将数字的小数位数扩展到最小值? [英] How to expand decimal places of a number to a minimum in Oracle PLSQL?
本文介绍了如何在Oracle PLSQL中将数字的小数位数扩展到最小值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
123 - >我不知道如何选择以下内容: 123.00000
123.12 - > 123.12000
123.123456 - > 123.123456
我想将小数位数扩展到例如5位小数(最小值)
如果根本没有小数位,则应该有5个零。
如果有5个以上的小数位,就可以了。
SELECT ROUND(123,5)FROM DUAL;
会导致123
而不是123.00000
该数字具有默认的精度。
这是可能的,还是应该将其转换为 oracle数字格式?
您可以使用以下内容:SQL> SELECT X,to_char(X,'fm99999999.00000999')
2 FROM(SELECT 123 X FROM dual UNION ALL
3 SELECT 123.12 FROM dual UNION ALL
4 SELECT 123.123456 FROM dual);
X TO_CHAR(X,'FM99999999.00000999
---------- ------------------- -----------
123 123.00000
123.12 123.12000
123.123456 123.123456
I cant figure out how to select the following:
123 -> 123.00000
123.12 -> 123.12000
123.123456 -> 123.123456
I would like to expand the number of decimal places to for example 5 decimal places (minimum) If there are no decimal places at all there should be 5 zeros. It is fine if there are more then 5 decimal places.
SELECT ROUND(123,5) FROM DUAL;
will result: 123 instead of 123.00000
The number has a default precision.
Is this possible or should I convert it to a varchar with the oracle number formats?
I am using Oracle 10g with plsql.
解决方案
You could use the following:
SQL> SELECT X, to_char(X, 'fm99999999.00000999')
2 FROM (SELECT 123 X FROM dual UNION ALL
3 SELECT 123.12 FROM dual UNION ALL
4 SELECT 123.123456 FROM dual);
X TO_CHAR(X,'FM99999999.00000999
---------- ------------------------------
123 123.00000
123.12 123.12000
123.123456 123.123456
这篇关于如何在Oracle PLSQL中将数字的小数位数扩展到最小值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文