登录
首页 >  数据库 >  MySQL

我们如何在同一查询中使用MySQL的LPAD()和RPAD()函数,将字符串的左侧和右侧都填充到原始字符串的两侧?

来源:tutorialspoint

时间:2023-08-22 16:26:07 180浏览 收藏

一分耕耘,一分收获!既然打开了这篇文章《我们如何在同一查询中使用MySQL的LPAD()和RPAD()函数,将字符串的左侧和右侧都填充到原始字符串的两侧?》,就坚持看下去吧!文中内容包含等等知识点...希望你能在阅读本文后,能真真实实学到知识或者帮你解决心中的疑惑,也欢迎大佬或者新人朋友们多留言评论,多给建议!谢谢!

For achieving this, we must have to use one of the functions as the 1st argument of the other function. In other words, either RPAD() function would be the 1st argument of LPAD() function or LPAD() function would be the 1st argument of RPAD() function. It can be understood with the help of the following example

Example

mysql> Select RPAD(LPAD(' My name is Ram ',23,'* '),30,'* ');
+------------------------------------------------+
| RPAD(LPAD(' My name is Ram ',23,'* '),30,'* ') |
+------------------------------------------------+
| * * * * My name is Ram * * * *                 |
+------------------------------------------------+
1 row in set (0.00 sec)

In the query above, LPAD() is the first argument of RPAD() function.

mysql> Select LPAD(RPAD(' My name is Ram ',23,'* '),30,'* ');
+------------------------------------------------+
| LPAD(RPAD(' My name is Ram ',23,'* '),30,'* ') |
+------------------------------------------------+
| * * * * My name is Ram * * * *                 |
+------------------------------------------------+
1 row in set (0.00 sec)

在上述查询中,RPAD() 是 LPAD() 函数的第一个参数。

好了,本文到此结束,带大家了解了《我们如何在同一查询中使用MySQL的LPAD()和RPAD()函数,将字符串的左侧和右侧都填充到原始字符串的两侧?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多数据库知识!

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>