Home > Database > Mysql Tutorial > How to use LPAD() and RPAD() functions in MySQL

How to use LPAD() and RPAD() functions in MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-26 18:13:25
forward
1747 people have browsed it

LPAD()/RPAD()

LPAD(str,len,padstr)The function indicates that the left side of the string str is filled with padstr until the length is len;RPAD(str,len,padstr)The function means padstr is used on the right side of the string str until the length is len. For example:

SELECT LPAD(123, 6, '0') AS str1, LPAD(123, 2, '0') AS str2,
       RPAD(123, 6, '0') AS str1, RPAD(123, 2, '0') AS str1;
str1  |str2|str1  |str1|
------+----+------+----+
000123|12  |123000|12  |
Copy after login

When the length of the string str is greater than len, it is equivalent to truncating the string from the right side.

In addition, the REPEAT(str,count) function is used to copy the string str count times and return the result. For example:

SELECT REPEAT('?', 5) AS str;
str       |
----------+
?????|
Copy after login

The above is the detailed content of How to use LPAD() and RPAD() functions in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template