oracle轉換數字到格式化字串,oracle字串

來源:互聯網
上載者:User

oracle轉換數字到格式化字串,oracle字串

問題描述
oracle如果儲存number(20,2)資料,0資料庫中為0.00,2.1資料庫中為2.10,3.88儲存為3.88,
如果直接從資料庫中取出對應顯示為:
0 2.1 3.88 保留兩位小數會發生變化,如果需要和資料庫保持一致:
解決方案
保留兩位有效小數的方法:

SELECT TO_CHAR(3.2,'FM99999999999990D00') FROM DUAL

廢話太多了,直接上例子:
參考執行個體:

select to_char(a, '99D90'),    to_char(a, '90D90'),    to_char(a, 'FM90D99'),    rtrim(to_char(a, 'FM90D99'), to_char(0, 'D'))from (    select 50 a from dual    union all select 50.57 from dual    union all select 5.57 from dual    union all select 0.35 from dual    union all select 0.4 from dual)order by a;TO_CHA TO_CHA TO_CHA RTRIM(------ ------ ------ ------   .35   0.35 0.35   0.35   .40   0.40 0.4    0.4  5.57   5.57 5.57   5.57 50.00  50.00 50.    50 50.57  50.57 50.57  50.57

參考文檔:

詳細參考:click here
官方文檔: oracle format doc
例子參考: example

相關文章

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.