MySQL LPAD Function
MySQL LPAD Function
In this tutorial, we will learn about MySQL LPAD Function with some examples. We can use this function to left pad with padding characters until it reaches length characters.
MySQL LPAD Function
LPAD() function returns the string with the specified characters as left padded to the original given string until it reaches the length.
Syntax
The general syntax of the function is as follows:
LPAD(<string>,<length>,<padding>)
Examples
Let’s use the function and check the output of the function in this example.
mysql> SELECT LPAD(‘MySQL’,20,’ ‘);
+———————-+
| LPAD(‘MySQL’,20,’ ‘) |
+———————-+
| MySQL |
+———————-+
1 row in set (0.00 sec)
mysql> SELECT LPAD(‘MySQL’,20,’&’);
+———————-+
| LPAD(‘MySQL’,20,’&’) |
+———————-+
| &&&&&&&&&&&&&&&MySQL |
+———————-+
1 row in set (0.00 sec)
In this example, let’s use the Country database table from the world MySQL database.
The column is the Name column that contains the country name. We will left pad the column values
with the * character.
mysql> SELECT Name, LPAD(Name,25,’*’)
-> FROM Country
-> WHERE Continent=’Asia’;
—
MySQL Tutorials
MySQL Tutorials on this website:
https://www.testingdocs.com/mysql-tutorials-for-beginners/
For more information on MySQL Database: