gloria@www.dweye.net>select trim(both'x'from'xxxxDWEYExxxx')"TRIM e.g."from dual; TRIM e.g -------- DWEYE gloria@www.dweye.net>select trim(trailing'x'from'xxxxDWEYExxxx')"TRIM e.g."from dual; TRIM e.g.------------ xxxxDWEYE gloria@www.dweye.net>select trim(leading'x'from'xxxxDWEYExxxx')"TRIM e.g."from dual; TRIM e.g.------------ DWEYExxxx
6 需要注意的地方
这里的“trim_character”参数只允许包含一个字符,不支持多字符。使用多字符的报错信息如下:
gloria@www.dweye.net>select trim(leading'xy'from'xyxxDWEYExyyx')"TRIM e.g."from dual;select trim(leading'xy'from'xyxxDWEYExyyx')"TRIM e.g."from dual * ERROR at line1: ORA-30001: trimset should have only onecharacter
既然TRIM不能满足我们删除只剩“DWEYE”字符串的要求,有么有其他手段呢?of course有。我们使用RTRIM和LTRIM“连环拳”完成这个任务。
1)使用RTRIM
gloria@www.dweye.net>select rtrim('xyxxDWEYExyyx','xy')"e.g."from dual; e.g.------------ xyxxDWEYE
2)使用LTRIM
gloria@www.dweye.net>select ltrim('xyxxDWEYExyyx','xy')"e.g."from dual; e.g.------------ DWEYExyyx
3)联合使用RTRIM和LTRIM函数达到我们的目的
gloria@www.dweye.net>select