Oracle如何顯示小數點前面的0

來源:互聯網
上載者:User

這幾天監控程式的健全狀態,發日誌在記錄0.開頭的小數時,都只顯示了 .*****,查看程式,是這樣用的:

select to_char(num) from AAAAAA,測試下:

SQL> select to_char(0.258) from dual;

TO_C
----
.258

確實用to_char()函數有這樣的問題,查下資料

TO_CHAR (number) converts n to a value of VARCHAR2 datatype, using the optional number format fmt. The value n can be of type NUMBER, BINARY_FLOAT, or BINARY_DOUBLE. If you omit fmt, then n is converted to a VARCHAR2 value exactly long enough to hold its significant digits.

原來to_char在做轉化時,如果你不指定可是,它就按它的格式去做轉化,結果就把0給轉不見了,所以在做轉化時要給定格式

SQL> SELECT to_char(0.2588,'fm999990.99999')  FROM  dual;

TO_CHAR(0.258
-------------
0.2588

那個9可以根據情況進行增減,格式的個位元字要是0,不然也會顯示不出來的。。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.