分类: Oracle
2008-01-11 19:14:05
18:50:50 SQL> SELECT TO_CHAR(9,'09') FROM DUAL;
TO_
---
09
用于获得分区名的语句, 其中9是根据一个公式算出来的值.
18:51:23 SQL> SELECT 'P'||TO_CHAR(9,'09') FROM DUAL;
'P'|
----
P 09
是显示问题? 不是, DUMP函数显示就是多了一个空格.
18:52:45 SQL> SELECT DUMP(TO_CHAR(9,'09')) coldump from dual;
COLDUMP
----------------------------------------
Typ=1 Len=3: 32,48,57
还有其他人遇到过吗? 帮忙测试一下? 用Perl或Java程序去执行这个查询, 返回值中一样多了个空格.
解释:
如果你觉得本文不错,可以订阅本站RSS | Google Reader | Bloglines | 抓虾 | 鲜果
SQL> SELECT 'P'||TO_CHAR(9,'FM09') FROM DUAL;
'P'|
----
P09
SQL> SELECT DUMP(TO_CHAR(9,'FM09')) coldump from dual;
COLDUMP
--------------------------------------------------------------------------------
Typ=1 Len=2: 48,57
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.