Skip to main content
Version: V1.0.0

RPAD

Syntax

RPAD(str,len,padstr)

Description

The RPAD function pads the string str on the right side with the string padstr until the total length reaches len.

  • If the length of str is greater than len, the function returns the leftmost len characters of str.

  • If the length of str is less than len and the combined length of str and padstr is greater than len, the function returns the leftmost len characters of the concatenated string.

  • If the length of str is less than len and the combined length of str and padstr is less than len, the function returns the leftmost len characters of the concatenated string after appending multiple copies of padstr to str until the total length is at least len.

Examples

SELECT RPAD('hi',5,'?');
+------------------+
| RPAD('hi',5,'?') |
+------------------+
| hi??? |
+------------------+
1 row in set (0.001 sec)

SELECT RPAD('hi',1,'?');
+------------------+
| RPAD('hi',1,'?') |
+------------------+
| h |
+------------------+
1 row in set (0.000 sec)