Home > Database > Mysql Tutorial > What will MySQL return if the length of the original string is greater than the length of the argument specified in the LPAD() or RPAD() function?

What will MySQL return if the length of the original string is greater than the length of the argument specified in the LPAD() or RPAD() function?

WBOY
Release: 2023-08-29 14:21:02
forward
686 people have browsed it

如果原始字符串的长度大于 LPAD() 或 RPAD() 函数中指定的参数长度,MySQL 将返回什么?

In this case, MySQL will not pad anything and will truncate characters from the original string up to the length value provided in the LPAD() or RPAD() function .

Example

mysql> Select LPAD('ABCD',3,'*');
+--------------------+
| LPAD('ABCD',3,'*') |
+--------------------+
| ABC                |
+--------------------+
1 row in set (0.00 sec)

mysql> Select RPAD('ABCD',3,'*');
+--------------------+
| RPAD('ABCD',3,'*') |
+--------------------+
| ABC                |
+--------------------+
1 row in set (0.00 sec)
Copy after login

From the above example we can observe that both functions do not fill "*", but truncate the original string to the specified length, that is, the parameter is 3.

The above is the detailed content of What will MySQL return if the length of the original string is greater than the length of the argument specified in the LPAD() or RPAD() function?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template