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      
posted @ 2021-03-01 16:10  harara  阅读(5398)  评论(0)    收藏  举报