1 概述
2 CHR(n) :返回 ascii值 对应的 字符
符号 | ASCII 码 | 释义 | 科普 |
---|---|---|---|
\t | 9 | 制表符 | |
\r | 10 | New Line(换行) | 换到下一行(并不一定是 首行) |
\n | 13 | Carriage Return(回车) | 回到 首行 |
32 | 空格符 |
with t_char as (
select 'a' || 'b' sname from dual union all
select 'a' || chr(9) || 'b' sname from dual union all
select 'a' || chr(10) || 'b' sname from dual union all
select 'a' || chr(13) || 'b' sname from dual union all
select 'a' || chr(32) || 'b' sname from dual
)
select t.sname 源数据,
lengthb(t.sname) 源长度长度,
regexp_replace(t.sname, '[ab]', '|') 去除字符ab,
ascii(regexp_replace(t.sname, '[ab]', '')) 特殊符号长度
from t_char t;
执行效果:
3 扩展
3.1 去除文本中的 空格、换行、回车
with t_char as (
select 'a' || 'b' sname from dual union all
select 'a' || chr(9) || 'b' sname from dual union all
select 'a' || chr(10) || 'b' sname from dual union all
select 'a' || chr(13) || 'b' sname from dual union all
select 'a' || chr(32) || 'b' sname from dual
)
select t.sname 源数据,
lengthb(t.sname) 源长度长度,
replace(replace(replace(replace(t.sname, chr(9), ''), chr(10), ''),
chr(13),
''),
chr(32),
'') 去除特殊符号,
lengthb(replace(replace(replace(replace(t.sname, chr(9), ''),
chr(10),
''),
chr(13),
''),
chr(32),
'')) 去除特殊符号后长度
from t_char t;
执行截图:
3.2 去除空格
with t_char as (
select ' ab' sname from dual union all
select ' ab ' sname from dual union all
select 'ab ' sname from dual
)
select t.sname 源数据,
'|' || trim(t.sname) || '|' 去除两端空格,
'|' || rtrim(t.sname) || '|' 去除右边空格,
'|' || ltrim(t.sname) || '|' 去除左边空格
from t_char t;
执行截图: