--時間轉化為字符串 select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual; --結果:2021-01-05 16:52:07 --數字轉字符串 select to_char(88877)from dual; --數字轉字符串,感覺沒什么用 select to_char(123456789,'099999999999999') from dual; --從右到左開始,不足就補充0,結果: 000000123456789 select to_char(123456789,'0999') from dual; --從右到左開始,當數字長度大於格式時,返回##### select to_char(123456789,'9999999999999') from dual; --不是0開始的。從右到左開始,不足就補充空格,結果: 123456789 select to_char(12345678,'0999,999,999,999') from dual; --轉為指定格式的字符串(只能逗號),結果: 0000,012,345,678 select to_char(12.31,'99.99999999') from dual; --給后面補0,結果: 12.31000000,當格式比數字短時,會截取數字再轉化為字符串 select to_char(1234567890,'0999,999,999,999.9999') from dual; --數字與格式結合;結果: 0001,234,567,890.0000
參考:https://blog.csdn.net/jiangnan2014/article/details/16908585
轉化的時候,結果的前面會出現一個空格,原因是這個是一個正負符號,當數字為正數的時候,返回的結果前面就會出現一個空格。當數字為負數時,返回的結果前面就是一個負號
例如下面
select to_char(-1234567890,'0999,999,999,999.9999') from dual;
最終的結果為:-0001,234,567,890.0000