登录
首页 >  数据库 >  MySQL

如何使用 MySQL LTRIM() 和 RTRIM() 函数同时删除字符串中的前导空格和尾随空格?

来源:tutorialspoint

时间:2023-08-27 12:38:17 109浏览 收藏

来到golang学习网的大家,相信都是编程学习爱好者,希望在这里学习数据库相关编程知识。下面本篇文章就来带大家聊聊《如何使用 MySQL LTRIM() 和 RTRIM() 函数同时删除字符串中的前导空格和尾随空格?》,介绍一下,希望对大家的知识积累有所帮助,助力实战开发!

For removing both leading and trailing spaces at once from a string by using LTRIM() and RTRIM() functions, we must have to use one function as an argument for other function. In other words, we must have to pass either LTRIM() function as an argument of RTIM() function or vice versa. It can be understood from the following example −

Example

Suppose we have a table ‘test_trim’ having a column ‘Name’ containing the values with leading and trailing spaces both −

mysql> Select * from test_trim;
+---------------+
| Name          |
+---------------+
| Gaurav        |
| Rahul         |
| Aarav         |
+---------------+
3 rows in set (0.00 sec)

现在,以下查询将使用LTRIM()和RTRIM()函数一次性从名称中删除前导和尾随空格 −

mysql> Select Name, LTRIM(RTRIM(Name))AS 'Name Without Spaces' from test_trim;
+---------------+---------------------+
| Name          | Name Without Spaces |
+---------------+---------------------+
| Gaurav        | Gaurav              |
| Rahul         | Rahul               |
| Aarav         | Aarav               |
+---------------+---------------------+
3 rows in set (0.00 sec)

mysql> Select Name, RTRIM(LTRIM(Name))AS 'Name Without Spaces' from test_trim;
+---------------+---------------------+
| Name          | Name Without Spaces |
+---------------+---------------------+
| Gaurav        | Gaurav              |
| Rahul         | Rahul               |
| Aarav         | Aarav               |
+---------------+---------------------+
3 rows in set (0.00 sec)

理论要掌握,实操不能落!以上关于《如何使用 MySQL LTRIM() 和 RTRIM() 函数同时删除字符串中的前导空格和尾随空格?》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

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