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’均做删除操作

作者:小念
出处:https://www.cnblogs.com/kiko2014551511/
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注