MySQL LPAD() Function
THE WORLD'S LARGEST WEB DEVELOPER SITE

MySQL LPAD() Function

❮ MySQL Functions

Example

Left-pad the string with "ABC", to a total length of 20:

SELECT LPAD("SQL Tutorial", 20, "ABC");
Try it Yourself »

Definition and Usage

The LPAD() function returns a string that is left-padded with a specified string to a certain length.

Note: Also look at the RPAD() function.

Syntax

LPAD(string, length, pad_string)

Parameter Values

Parameter Description
string Required. The string to left-pad
length Required. The length of the string after it has been left-padded
pad_string Required. The string to left-pad to string

Note: If string is longer than length, the LPAD() function will remove the over floating characters from string.

Technical Details

Works in: MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23

More Examples

Example

Left-pad the text in "CustomerName" with "ABC", to a total length of 30:

SELECT LPAD(CustomerName, 30, "ABC") AS LeftPadCustomerName
FROM Customers;
Try it Yourself »

❮ MySQL Functions