首页 > 数据库 > Oracle > to char前面多出空格 360@365

to char前面多出空格 360@365

Oracle 作者:huanyue85 时间:2013-12-27 22:31:28 0 删除 编辑

SQL> select to_char(10,'00') from dual;

 10      --前面有一个空格,这是一个正数的符号位

SQL> select length(to_char(10,'00')) from dual;

                       3       --所以长度是3

解决方法 :要么加 fm 要么加 trim

SQL> select length(to_char(10,'fm00')) from dual;


SQL> select length(trim(to_char(10,'00'))) from dual;


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博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录