度量快速开发平台-专业、快速的软件定制快开平台

标题: oracle正则表达式实战 [打印本页]

作者: 张兴康    时间: 2020-5-6 18:04
标题: oracle正则表达式实战
create table test(mc varchar2(60));

insert into test values('112233445566778899');
insert into test values('22113344 5566778899');
insert into test values('33112244 5566778899');
insert into test values('44112233 5566 778899');
insert into test values('5511 2233 4466778899');
insert into test values('661122334455778899');
insert into test values('771122334455668899');
insert into test values('881122334455667799');
insert into test values('991122334455667788');
insert into test values('aabbccddee');
insert into test values('bbaaaccddee');
insert into test values('ccabbddee');
insert into test values('ddaabbccee');
insert into test values('eeaabbccdd');
insert into test values('ab123');
insert into test values('123xy');
insert into test values('007ab');
insert into test values('abcxy');
insert into test values('The final test is is is how to find duplicate words.');

commit;

一、REGEXP_LIKE

select * from test where regexp_like(mc,'^a{1,3}');
select * from test where regexp_like(mc,'a{1,3}');
select * from test where regexp_like(mc,'^a.*e$');
select * from test where regexp_like(mc,'^[[:lower:]]|[[:digit:]]');
select * from test where regexp_like(mc,'^[[:lower:]]');
Select mc FROM test Where REGEXP_LIKE(mc,'[^[:digit:]]');
Select mc FROM test Where REGEXP_LIKE(mc,'^[^[:digit:]]');

二、REGEXP_INSTR

Select REGEXP_INSTR(mc,'[[:digit:]]$') from test;
Select REGEXP_INSTR(mc,'[[:digit:]]+$') from test;
Select REGEXP_INSTR('The price is $400.','$[[:digit:]]+') FROM DUAL;
Select REGEXP_INSTR('onetwothree','[^[[:lower:]]]') FROM DUAL;
Select REGEXP_INSTR(',,,,,','[^,]*') FROM DUAL;
Select REGEXP_INSTR(',,,,,','[^,]') FROM DUAL;

三、REGEXP_SUBSTR

SELECT REGEXP_SUBSTR(mc,'[a-z]+') FROM test;
SELECT REGEXP_SUBSTR(mc,'[0-9]+') FROM test;
SELECT REGEXP_SUBSTR('aababcde','^a.*b') FROM DUAL;

四、REGEXP_REPLACE

Select REGEXP_REPLACE('Joe Smith','( ){2,}', ',') AS RX_REPLACE FROM dual;
Select REGEXP_REPLACE('aa bb cc','(.*) (.*) (.*)', '3, 2, 1') FROM dual;


作者: 陈晓龙    时间: 2020-5-7 17:15

作者: 张兴康    时间: 2020-5-13 14:39
陈晓龙 发表于 2016-6-7 17:15

好闪的牙
作者: 陈晓龙    时间: 2020-5-13 16:48
张兴康 发表于 2016-6-13 14:39
好闪的牙

呵呵
作者: 张兴康    时间: 2020-5-14 16:45
陈晓龙 发表于 2016-6-13 16:48
呵呵

差点闪瞎我的眼
作者: 陈晓龙    时间: 2020-5-15 14:28
张兴康 发表于 2016-6-14 16:45
差点闪瞎我的眼

呵呵!
作者: 张兴康    时间: 2020-5-15 17:11
陈晓龙 发表于 2016-6-15 14:28
呵呵!


作者: 陈晓龙    时间: 2020-5-16 16:27
张兴康 发表于 2016-6-15 17:11


作者: 张兴康    时间: 2020-5-16 17:22
陈晓龙 发表于 2016-6-16 16:27


作者: 万望    时间: 2020-6-4 17:02
正则表达式有点复杂记不住啊
作者: 张兴康    时间: 2020-6-4 18:25
万望 发表于 2016-8-4 17:02
正则表达式有点复杂记不住啊

所以要收藏以备不时之需噻




欢迎光临 度量快速开发平台-专业、快速的软件定制快开平台 (http://plat.delit.cn/) Powered by Discuz! X3.2