The RPAD function pads the right side of a string with a specific set of characters.
RPAD( char1, n, [, char2 ] )
The RPAD function pads the right side of char1 with char2 until its length reaches n.
- char1 : Specifies the string to pad characters to. If the length of char1 is greater than n, char1 is returned truncated to the length of n. If char1 is truncated at the first byte of a double-byte character set (e.g. Korean), the first byte is removed and then a space character is added. If the value is NULL, NULL is returned.
- n : Specifies the length. If the value is NULL, NULL is returned.
- char2 : Specifies the string to pad. The default value for char2 is a single space character (' '). If the value is NULL, NULL is returned.
- Example 1
- The following is an example that pads the character X on the right of a string until the length of the string reaches 6.
SELECT RPAD('123', 6, 'X') FROM db_root;
- Example 2
- The following is an example that truncates a string to the length of 4 and returns the result.
SELECT RPAD('123456', 4, 'X') FROM db_root;