LPAD( )

This MySQL function adds padding to the left 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).

LPAD(string, length, padding)

Explanation

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

Examples

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

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

In this example, a list of three courses is retrieved and the results are padded with dots to the left of the course names.