如何以所需格式显示十进制值?

时间:2016-02-22 09:06:08

标签: sql oracle

SELECT TO_NUMBER(TO_CHAR( '0.200','999.999')) AS NUM_ FROM DUAL;

如何显示0.200?

3 个答案:

答案 0 :(得分:0)

根据你的例子:

SELECT TO_CHAR(TO_NUMBER( '0.200','999.999'), 'fm0.000') AS NUM_ 
FROM DUAL;

您可以将其简化为:

SELECT TO_CHAR(0.2, 'fm0.000') AS NUM_ 
FROM DUAL;

答案 1 :(得分:0)

个人SQL语句级别:

SQL> SELECT TO_CHAR(.2, 'fm0.000') num FROM DUAL;

NUM
------
0.200

SQL>

在SQL * Plus中:

SQL> set numformat 0.999
SQL> SELECT .2 num FROM DUAL;

   NUM
------
 0.200

SQL>

我建议使用 TO_CHAR 和所需的格式模型,以所需的格式显示数字。

答案 2 :(得分:-3)

SELECT TRIM(TO_CHAR( '0.200','990.999')) AS NUM_
    FROM DUAL