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
WBOYforward
2023-08-29 14:21:02691browse

如果原始字符串的长度大于 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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete