RPAD
Pads a string on the right with another string up to the given length.
MySQL 8.1
RPAD(str, len, pad_str)- str
- Source stringVARCHAR
- len
- Length of the result in charactersINT
- pad_str
- String used to pad strVARCHAR
Return value
A string of len characters; a longer str is cut on the right to len characters; NULL for a negative len; an empty string if pad_str is empty but padding is needed
Examples
Zeros on the right to a length
MySQL 8.1
SELECT RPAD('9', 5, '0');Cutting a long string
MySQL 8.1
SELECT RPAD('hello', 3, '*');Aligning names with dots
MySQL 8.1
SELECT RPAD(member_name, 20, '.') AS name,
status
FROM FamilyMembers;Details
If pad_str is longer than needed, only its beginning is used: RPAD('5', 4, 'ab') returns 5aba. The length is counted in characters, so the alignment also works for Cyrillic.