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;--清空
-- 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;--清空
相关文章推荐
- ORACLE 更新关联多张表
- Missing artifact com.oracle:ojdbc14:jar:10.2.0.4.0.jar的问题
- windows运维脚本:通过vbscript更新excel文档oracle数据源
- oracle笔记整理15——性能调优之trace文件跟踪
- oracle笔记整理14——性能调优之oracle执行计划
- oracle笔记整理13——性能调优之SQL优化
- 【转】 oracle cast multiset table 语法演示
- 【转】Oracle的伪列
- 【转】ORACLE的HINT详解
- oracle笔记整理12——性能调优之hint标签
- oracle笔记整理11——性能调优之oracle等待事件与表关联
- C#Winform连接Oracle数据库
- C# 调用 Oracle
- oracle
- Centos6安装oracle
- oracle over()分析函数的使用实例
- 关于判断oracle中变量为空和空字符串
- 数据库访问性能优化 Oracle
- 关于oracle服务器重启后不能工作的解决方法
- ORACLE 更改username