1. 程式人生 > >oracle的to_char中的fm

oracle的to_char中的fm

SQL> select '|'||to_char(5,'999')||'|' from dual;
 結果為:|   5|

SQL> select '|'||to_char(5,'000')||'|' from dual;
 結果為:| 005|

SQL> select '|'||to_char(-5,'000')||'|' from dual;
 結果為:|-005|
 
 可見:前面的空格是為+號留的位置,只是為+號時省略了。
 如何去除多餘的空格?
 SQL> select '|'||to_char(5,'fm000')||'|' from dual;
 結果為:|005|
 
空格沒有了,fm主要作用就是去除空格的影響。

10進位制轉換成16進位制:
SQL> select '|'||to_char(32,'fmxxxxxxx')||'|' from dual;
 結果為:|20|
 
 16進位制轉換成10進位制:
 SQL> select '|'||to_number(20,'xxxxxxxxx')||'|' from dual;
 結果為: |32|