您的位置:首页 > 数据库 > Oracle

oracle正则表达式

2016-01-17 15:11 405 查看
技术的语言最真诚!

-- count regexp_count

create or replace view v as

select 'clarl,king,minl' as str,10 as dept from dual

select count(*) from v--计算总记录

select regexp_count(str,',') from v--出现的次数

--substr regexp_substr

select substr('adsf',1,3) from dual;--截取

select regexp_substr('asdf,rtuy,trewq','[^,]+',1,2) from dual;

--replace regexp_replace

select replace('asdfgh','f','') from dual;

select regexp_replace('asdfgh','[^f]+','') from dual;

--like regexp_like

select * from v where str like('%i%')

select * from v where regexp_like(str,'g$')--以g结束的

select * from v where regexp_like(str,'^c')--以c开头的

select * from v where regexp_like(str,'^clarl$')--等价于普通 select * from v where str like('clarl')

--合并 listagg

create or replace view v as

select 'clarl' as str,10 as dept from dual

union all

select 'king' as str,10 as dept from dual

union all

select 'minll' as str,10 as dept from dual

(SELECT DEPT,LISTAGG(str,',') within group(order by str) "test" from v group by dept)

--拆分

create or replace view v as

select 'clarl,king,minl' as str,10 as dept from dual;

select regexp_substr(str,'[^,]+',1,level)as newstr,dept from v where dept =10 connect by level <=regexp_count(str,',')+1

--其他函数

--单引号

select 'g''day mate' qmarks from dual;

--translate 删除不需要的字符 替换函数

select translate('hello word hello','asdfh','1234') from dual; -- a-->1,s-->2,d-->3,f-->4,h-->''进行替换

select translate('hello word hello','asdf','') from dual;--清空
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: