This tutorial explains how to use the MySQL LPAD function with syntax and examples.
The MySQL LPAD function returns a string that is left-padded with a specified string to a certain length.
The syntax for the LPAD function in MySQL is:
LPAD( string, length, pad_string )
The string to left-pad.
The length of the result after string has been left-padded.
The specified string to left-pad to string.
The LPAD function can be used in the following versions of MySQL:
Let's look at some MySQL LPAD function examples and explore how to use the LPAD function in MySQL.
For example:
mysql> SELECT LPAD('AODBA.com', 18, 'A');
Output: 'AAAAAAAAAAODBA.com'
mysql> SELECT LPAD('AODBA.com', 19, 'A');
Output: 'AAAAAAAAAAAODBA.com'
mysql> SELECT LPAD('abc', 6, ' ');
Output: ' abc'
mysql> SELECT LPAD('abc', 9, 'XYZ');
Output: 'XYZXYZabc'
mysql> SELECT LPAD('abc', 10, 'XYZ');
Output: 'XYZXYZXabc'