The RPAD function returns an expression, right-padded to a specified length with the specified characters; or, when the expression to be padded is longer than the length specified after padding, only that portion of the expression that fits into the specified length.

Length

The total length of the return value as it is displayed on your terminal screen. In most character sets, this is also the number of characters in the return value. However, in some multibyte character sets, the display length of a character string can differ from the number of characters in the string.

When you specify a value for length that is shorter than the length of text-exp, then this function truncates the expression to the specified length.

SQL> SELECT '甲骨文' ORA_STR,
2         LENGTHB('甲骨文') ORA_STR_LENGTH,
3         RPAD('甲骨文', 10, '$') ORA_RPAD_STR, 4 LENGTHB(RPAD('甲骨文', 10, '$')) ORA_RPAD_STR_LENGTH
5    FROM dual
6  ;

--------- -------------- ------------- -------------------

SQL> 

SQL> SELECT '甲骨文' ORA_STR,
2         LENGTHB('甲骨文') ORA_STR_LENGTH,
3         RPAD('甲骨文', 10, '$') ORA_RPAD_STR, 4 LENGTHB(RPAD('甲骨文', 10, '$')) ORA_RPAD_STR_LENGTH,
5         -- 解决方法
6         SUBSTRB('甲骨文' || RPAD('$', 10, '$'), 1, 10) SOLUTION
7    FROM dual
8  ;

--------- -------------- ------------- ------------------- ----------

-----------------------

SQL> 

参考链接

posted @ 2013-11-29 15:52 eliuhy 阅读(...) 评论(...) 编辑 收藏