RPAD( )

This MySQL function adds padding to the right end of string, stopping if the combination of string and the added padding reach length characters.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

RPAD(string, length, padding)

Explanation

This function adds padding to the right end of string, stopping if the combination of string and the added padding reach length characters. If the length given is shorter than the length of the string, the string will be shortened to comply with the length constraint. The padding can be any character.

Examples

SELECT RPAD(course_name, 25, '.') AS Courses
FROM courses
WHERE course_code LIKE 'ENGL%'
LIMIT 3;

+---------------------------+
| Courses                   |
+---------------------------+
| Creative Writing......... |
| Professional Writing..... |
| American Literature...... |
+---------------------------+

This statement presents a list of three course names that are retrieved. Each row of the results is padded with dots to the right.