这个参数改变了“删除空格”的默认行为。
如果想要删除字符串'xxxxSZTECHxxxx'前后出现的“x”,“trim_character”参数就派上用场了。
gloria@www.cqsztech.com> select trim ('x' from 'xxxxSZTECHxxxx') "TRIM e.g." from dual;
TRIM e.g
--------
SZTECH
配合“BOTH”、“TRAILING”和“LEADING”三个参数使用效果如下,与之前演示类似。看结果,不赘述。
gloria@www.cqsztech.com> select trim (both 'x' from 'xxxxSZTECHxxxx') "TRIM e.g." from dual;
TRIM e.g
--------
SZTECH
gloria@www.cqsztech.com> select trim (trailing 'x' from 'xxxxSZTECHxxxx') "TRIM e.g." from dual;
TRIM e.g.
------------
xxxxSZTECH
gloria@www.cqsztech.com> select trim (leading 'x' from 'xxxxSZTECHxxxx') "TRIM e.g." from dual;
TRIM e.g.
------------
SZTECHxxxx
6.需要注意的地方
这里的“trim_character”参数只允许包含一个字符,不支持多字符。
报错信息如下:
gloria@www.cqsztech.com> select trim (leading 'xy' from 'xyxxSZTECHxyyx') "TRIM e.g." from dual;
select trim (leading 'xy' from 'xyxxSZTECHxyyx') "TRIM e.g." from dual
*
ERROR at line 1:
ORA-30001: trim set should have only one character
既然TRIM不能满足我们删除只剩“SZTECH”字符串的要求,有么有其他手段呢?of course有。我们使用RTRIM和LTRIM“连环拳”完成这个任务。
1)使用RTRIM
gloria@www.cqsztech.com> select rtrim('xyxxSZTECHxyyx','xy') "e.g." from dual;
e.g.
------------
xyxxSZTECH
2)使用LTRIM
gloria@www.cqsztech.com> select ltrim('xyxxSZTECHxyyx','xy') "e.g." from dual;
e.g.
------------
SZTECHxyyx
3)联合使用RTRIM和LTRIM函数达到我们的目的
gloria@www.cqsztech.com> select ltrim(rtrim('xyxxSZTECHxyyx','xy'),'xy') "e.g." from dual;