oracle to char trim,to_char前面多出空格
to_char前面多出空格
用to_char對數(shù)字時前面會多出一個空格。
SQL> select to_char(10,'00') from dual;
TO_
---
10 ? ? ?--前面有一個空格,這是一個正數(shù)的符號位
SQL> select length(to_char(10,'00')) from dual;
LENGTH(TO_CHAR(10,'00'))
------------------------
3 ? ? ? --所以長度是3
解決方法 :要么加 fm 要么加 trim
SQL> select length(to_char(10,'fm00')) from dual;
LENGTH(TO_CHAR(10,'FM00'))
--------------------------
2
SQL> select length(trim(to_char(10,'00'))) from dual;
LENGTH(TRIM(TO_CHAR(10,'00')))
------------------------------
2
網(wǎng)上有:
FM Fill mode. Oracle uses blank characters to fill format elements to a constant width equal to the largest element for the relevant format model in the current session language. For example, when NLS_LANGUAGE is AMERICAN, the largest element for MONTH is SEPTEMBER, so all values of the MONTH format element are padded to 9 display characters. This modifier suppresses blank padding in the return value of the TO_CHAR function: In a datetime format element of a TO_CHAR function, this modifier suppresses blanks in subsequent character elements (such as MONTH) and suppresses leading zeroes for subsequent number elements (such as MI) in a date format model. Without FM, the result of a character element is always right padded with blanks to a fixed length, and leading zeroes are always returned for a number element. With FM, which suppresses blank padding, the length of the return value may vary. In a number format element of a TO_CHAR function, this modifier suppresses blanks added to the left of the number, so that the result is left-justified in the output buffer. Without FM, the result is always right-justified in the buffer, resulting in blank-padding to the left of the number.
來自 “ ITPUB博客 ” ,鏈接:http://blog.itpub.net/25099483/viewspace-1064823/,如需轉(zhuǎn)載,請注明出處,否則將追究法律責任。
總結(jié)
以上是生活随笔為你收集整理的oracle to char trim,to_char前面多出空格的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微软私有云解决方案_微软发布电信云平台
- 下一篇: css中变形,css3中变形处理