Curriculum
Course: MYSQL
Login

Curriculum

MYSQL

MySQL References

0/140
Text lesson

LPAD

Example

Pad the string on the left side with “ABC” until it reaches a total length of 20 characters.

SELECT LPAD(“SQL Tutorial”20“ABC”); 

Definition and Usage

The LPAD() function adds padding to the left side of a string with another string until it reaches a specified length.

Note: Additionally, consider the RPAD() function for padding on the right side.

Syntax

LPAD(stringlengthlpad_string)

Parameter Values

Parameter

Description

string

Input required: The original string. If the length of the original string exceeds the specified length parameter, this function removes any overflowing characters from the string.

length

Input required: The desired length of the string after left-padding has been applied.

lpad_string

Input required: The string used for left-padding.

Technical Details

Works in: From MySQL 4.0

More Examples

Example

Pad the text in the “CustomerName” column on the left side with “ABC” until it reaches a total length of 30 characters.

SELECT LPAD(CustomerName, 30“ABC”AS LeftPadCustomerName
FROM Customers;