oracle替换指定字符集正则表达式

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

REGEXP_REPLACE:搜索并且替换匹配的正则表达式
(srcstr, pattern [, replacestr [, position [, occurrence [, match_option]]]])
其中各参数的含义为:
srcstr: 被查找的字符数据,可以是列和绑定变量等
pattern: 正则表达式。
occurrence: 出现的次数。默认为1。
position: 开始位置
return_option: 默认值为0,返回该模式的起始位置;值为1则返回符合匹配条件的下一个字符的起始位置。
replacestr: 用来替换匹配模式的字符串。
match_option: 匹配方式选项。缺省为c。
c:case sensitive
I:case insensitive
n:(.)匹配任何字符(包括newline)
m:字符串存在换行的时候被作为多行处理
下面通过一些具体的例子来说明如何使用这四个函数。在测试当中,你就会逐步的体会到这些正则表达式的优势
首先创建测试表TEST,并加载测试数据:
scott@DB01> create table test (c1 int , testcol varchar2(100));
Table created.
scott@DB01> insert into test values(100,'10d6h2');
1 row created.
scott@DB01> insert into test values(110,'100025');
1 row created.
scott@DB01> insert into test values(120,'gift');
1 row created.
scott@DB01> insert into test values(130,'010********');
1 row created.
scott@DB01> insert into test values(140,'010-400-7591');
1 row created.
scott@DB01> insert into test values(150,'ab c de');
1 row created.
scott@DB01> insert into test values(160,'abcde');
1 row created.
scott@DB01> insert into test values(170,'tianjie@'|| chr(10) ||'liuy@');
1 row created.
scott@DB01> insert into test values(180,'Steven');
1 row created.
scott@DB01> insert into test values(190,'bac');
1 row created.
scott@DB01> insert into test values(200,'Stephen');
1 row created.
scott@DB01> commit;
Commit complete.

scott@DB01> col testcol for a60
scott@DB01> select * from test;
C1 TESTCOL
------------------------------------------------------------
100 10d6h2
110 100025
120 gift
130 010********
140 010-400-7591
150 ab c de
160 abcde
170 tianjie@
liuy@
180 Steven
190 bac
200 Stephen
11 rows selected.



select regexp_replace('10d6h2','[^[:digit:]]',0) from dual


select regexp_replace('tianjie I am','(.*) (.*) (.*)','\2 \3 \1!') from dual;


select regexp_replace('aa bb cc ','(.*) (.*) (.*)','\3 \2 \1!') from dual;




















相关文档
最新文档