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