如何在sql语句中使用Oracle regexp仅删除尾随空格和chr(10)和chr(13)?
示例:
with txt as (select chr(10)||chr(10)||' Hey Bob '||chr(10)||chr(13) a from dual)
select a
,regexp_replace(a,chr(10)||'+|'||chr(13)||'+|'||chr(32)||'+$','')
,regexp_replace(a,'['||chr(10)||'+'||chr(13)||'+'||chr(32)||'+]$','')
from txt;
期望的结果:
' Hey Bob'
1. Leading and non-trailing spaces remain
2. Trailing spaces and eol characters removed
答案 0 :(得分:4)
最好使用[[:space:]]
来捕获所有空格:
regexp_replace(a, '[[:space:]]+$', '')
但是如果你只是明确地想要换行符(10),回车符(13)和空格(32),你可以这样做:
regexp_replace(a, '[' || chr(10) || chr(13) || ' ]+$', '')
-- ^-- space character.