ITPub博客

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

to char前面多出空格 360@365

Oracle 作者:huanyue85 时间:2013-12-27 22:31:28 0 删除 编辑
to_char前面多出空格

用to_char对数字时前面会多出一个空格。
SQL> select to_char(10,'00') from dual;

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

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                       
                             

网上有:http://www.huomo.cn/database/article-ce7a.html
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/22310632/viewspace-1115835/,如需转载,请注明出处,否则将追究法律责任。

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

注册时间:2009-08-10

最新文章