
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 −
Jenni AI
使用最先进的 AI 写作助手为您的写作增光添彩。
48 查看详情
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() 函数同时删除字符串中的前导空格和尾随空格?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/751136.html
微信扫一扫
支付宝扫一扫