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