Mysql函数->TRIM(去掉首尾空格、任意字符)


 

TRIM

语法

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str)

序号 函数                                                  函数结果       备注
1 trim(' test ') 'test' 删除字符串前后空格
2 trim(both from ' test ') 'test' 'both'参数表示同时去除字符串前后所指定的内容(默认情况下删除空格)
3 trim(trailing from ' test ') ' test' 'trailing'参数表示删除字符串尾部空格
4 trim(leading from ' test ') 'test ' 'leading'参数表示删除字符串头部空格
5 trim('x' from 'xxxtestxxx') 'test' 删除字符串前后的字符'x' 
6 trim(both 'x' from 'xxxtestxxx') 'test' 删除字符串前后的字符'x'
7 trim(trailing 'xy' from  'xyxyxtestxxyxy') 'xyxyxtestx' 删除字符串尾部的字符串'xy'
8 trim(leading 'xy' from 'xyxyxtestxxyxy') 'xtestxxyxy' 删除字符串头部的字符串'xy'
9 trim(leading 'xy' from trim(trailing 'xy' from  'xyxtestxxy')) 'xtestx' 删除字符串头尾的字符'xy'

 

LTRIM / RTRIM 

去掉字符串左/右边的空格

序号 函数                         函数结果     备注                              
1 ltrim(' test ') 'test ' 去掉字符串左边的空格
2 rtrim(' test ') ' test' 去掉字符串右边的空格
3      


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM