RPAD
Descriptionβ
Used to pad the specified character on the right side of the original string until met the specified length.
Syntaxβ
RPAD ( <str> , <len> , <pad>)
Parametersβ
Parameter | Description |
---|---|
<str> | The string to be padded. |
<len> | The total length of the final result string, which represents character length rather than the byte length. |
<pad> | The string used for padding. |
Return Valueβ
Returns the padded string. Special cases:
- If any Parameter is NULL, NULL will be returned.
- If
<pad>
is empty and<len>
is greater than the length of<str>
, the return value is an empty string. - If
<len>
is less than the length of<str>
, the string obtained by truncating<str>
to<len>
is returned. - If
<len>
is less than 0, the return value is NULL.
Examplesβ
SELECT rpad('hello', 1, '');
+----------------------+
| rpad('hello', 1, '') |
+----------------------+
| h |
+----------------------+
SELECT rpad('hello', 10, 'world');
+----------------------------+
| rpad('hello', 10, 'world') |
+----------------------------+
| helloworld |
+----------------------------+
SELECT rpad('hello', 10, '');
+-----------------------+
| rpad('hello', 10, '') |
+-----------------------+
| |
+-----------------------+