Oracle函數->TRIM(去掉首尾空格、首尾字符)


 

TRIM

語法:

TRIM([ { { LEADING | TRAILING | BOTH }[ trim_character ]| trim_character } FROM ] trim_source)

 

序號 函數                                                  函數結果       備注
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 'x' from  'xxxtestxxx') 'xxxtest' 刪除字符串尾部的字符'x'
8 trim(leading 'x' from 'xxxtestxxx') 'testxxx' 刪除字符串頭部的字符'x'
       
       

 

 注意: 'trim_character'參數只允許包含一個字符,不支持多個字符。多個字符報錯信息如下

 trim不能滿足我們去除多字符要求,但是我們可以使用rtrim和ltrim來處理

 

 

LTRIM /RTRIM

序號 函數                                                              函數結果           備注                                                                           
 1  rtrim('xyxxtestxyyx','xy') 'xyxxtest'   刪除字符串右邊的'xy'字符
 2  ltrim('xyxxtestxyyx','xy') 'testxyyx'   刪除字符串左邊的'xy'字符
 3  ltrim(rtrim('xyxxtestxyyx','xy'),'xy')  'test'  刪除字符串左右兩邊的'xy'字符
 4      
       

 

注意:使用LTRIM和RTRIM函數時的注意事項:'xy'不表示整個'xy'字符串進行匹配,而是發現任意的字符'x'或字符'y'均做刪除操作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM