Function Reference

RPAD

Pads a string on the right with another string up to the given length.

MySQL 8.1
RPAD(str, len, pad_str)

Parameters

strVARCHAR
Source string
lenINT
Length of the result in characters
pad_strVARCHAR
String used to pad str

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');
RPAD('9', 5, '0')
90000

Cutting a long string

MySQL 8.1
SELECT RPAD('hello', 3, '*');
RPAD('hello', 3, '*')
hel

Aligning names with dots

MySQL 8.1
SELECT RPAD(member_name, 20, '.') AS name,
	status
FROM FamilyMembers;
namestatus
Headley Quincey.....father
Flavia Quincey......mother
Andie Quincey.......son
Lela Quincey........daughter
Annie Quincey.......daughter
Ernest Forrest......father
Constance Forrest...mother
Wednesday Addams....daughter

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.

See also