number----char(to_char)
1,number----char(to_char)
一個數字在轉成字元型別,在指定了格式時正數會多一個位元組用來儲存前面的‘+’
SQL> select length(23),length(-23) from dual;
LENGTH(23) LENGTH(-23)
---------- -----------
2 3
SQL> select length(to_char(23)),length(to_char(-23)) from dual;
LENGTH(TO_CHAR(23)) LENGTH(TO_CHAR(-23))
------------------- --------------------
2 3
SQL> select length(to_char(23,'99')),length(to_char(-23,'99')) from dual;
LENGTH(TO_CHAR(23,'99')) LENGTH(TO_CHAR(-23,'99'))
------------------------ -------------------------
3 3
多出的佔位符用空格補充
SQL> select length(to_char(23,'S99')),length(to_char(0,'S99')) from dual;
LENGTH(TO_CHAR(23,'STM9')) LENGTH(TO_CHAR(0,'S99'))
-------------------------- ------------------------
3 3
可以透過使用‘S’來顯示‘+’
SQL> select to_char(23,'S99'),to_char(-23,'S99') from dual;
TO_CHAR(23,'S99') TO_CHAR(-23,'S99')
----------------- ------------------
SQL> select length(to_char(23,'TM9')),length(to_char(-23,'TM9')) from dual;
LENGTH(TO_CHAR(23,'TM9')) LENGTH(TO_CHAR(-23,'TM9'))
------------------------- --------------------------
2 3
TM最小格式輸出,會去掉空格以及前面的‘+’,同不帶格式引數一樣
SQL> select length(to_char(23,'TM9')),length(to_char(-23,'TM9')) from dual;
LENGTH(TO_CHAR(23,'TM9')) LENGTH(TO_CHAR(-23,'TM9'))
------------------------- --------------------------
2 3
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29609161/viewspace-2676371/,如需轉載,請註明出處,否則將追究法律責任。