Oracle:格式化显示的十进制数

时间:2015-09-24 07:48:02

标签: sql oracle

我想在oracle中使用to_char函数显示十进制数列表,但我不知道怎么办..

SELECT REGEXP_REPLACE(TO_CHAR(-11111.1,'fm000000000D999999999'),'^\.','0.')  FROM dual;

结果:

-000011111.1 

我可以知道如何打印出如下的十进制列表标准模式吗?您可能希望范围的十进制数是'999999.999999'。感谢。

Negative decimal number --------------------

-000011111.1  --> -11111.1
-0.1          --> -0.1
-0000.1       --> -0.1
-1.1000       --> -1.1


Positive decimal number ---------------------

000011111.1  --> 11111.1
0.1          --> 0.1
0000.1       --> 0.1
1.1000       --> 1.1

2 个答案:

答案 0 :(得分:2)

我正在使用to_char这种格式,并且还没有问题。
'FM99999999999999990.0'
关键是在点之前加零。

希望这有帮助。

答案 1 :(得分:1)

SELECT rtrim(TO_CHAR(NUM,'99999999990D9999999999'),'0.')  FROM 
(SELECT -000011111.1 AS NUM FROM dual UNION ALL
 SELECT -0.1         AS NUM FROM dual UNION ALL
 SELECT -0000.1      AS NUM FROM dual UNION ALL
 SELECT -1.1000      AS NUM FROM dual UNION ALL
 SELECT 000011111.1  AS NUM FROM dual UNION ALL
 SELECT 0.1          AS NUM FROM dual UNION ALL
 SELECT 1            AS NUM FROM dual UNION ALL
 SELECT 0000.1       AS NUM FROM dual UNION ALL
 SELECT 1.1000       AS NUM FROM dual);