码迷,mamicode.com
首页 > 数据库 > 详细

oracle11g的regexp函数

时间:2018-04-27 13:28:02      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:--   over   null   tno   drop   一个   指定   ace   oracle11g   

1.判断是否是数字 regexp_Like

select * from (
select ‘abc‘ s1 from dual
union all select ‘789456‘ s1 from dual
union all select ‘8907a7‘ s1 from dual
union all select ‘3‘ s1 from dual
union all select ‘‘ s1 from dual
union all select null s1 from dual
) where regexp_Like(s1,‘^[0-9]+$‘)
;

2.指定字符是否在字符串存在  regexp_instr

--需求,为每笔交易的基金找个账号,优先取席位的专用账号,若多个席位匹配多个账号则随机取一个,没有席位的专用账号则取容错账号

drop table t_regexp_instr_account;

create table t_regexp_instr_account as

select ‘110001‘ fundid,‘110001的专用账号1‘ accountno,‘a001,b005,a002,d008‘ seatid from dual

union all select ‘110002‘,‘110002的容错账号‘,‘‘ from dual

union all select ‘110001‘,‘110001的容错账号‘,‘‘ from dual

union all select ‘110001‘,‘110001的c005专用账号‘,‘c005‘ from dual

union all select ‘110003‘,‘110003的b005专用账号‘,‘b005‘ from dual

union all select ‘110003‘,‘110003的容错账号‘,‘‘ from dual

union all select ‘110004‘,‘110004的a004专用账号‘,‘a004‘ from dual

union all select ‘110004‘,‘110004的容错账号‘,‘‘ from dual ;

drop table t_regexp_instr_trade;

create table t_regexp_instr_trade as

select ‘110001‘ fundid,‘a002,c005‘ seatid from dual

union all select ‘110002‘ fundid,‘a001‘ seatid from dual

union all select ‘110003‘ fundid,‘c007,b006‘ seatid from dual

union all select ‘110004‘ fundid,‘a004,b005‘ seatid from dual ;

--不用正则表达式

select * from t_regexp_instr_account a,t_regexp_instr_trade b where a.fundid=b.fundid and regexp_instr(a.seatid,b.seatid)>0 ;

--使用正则表达式可以达到效果 |代表或者

select * from (   select row_number() over (partition by a.fundid order by a.seatid nulls last) rid,a.* from t_regexp_instr_account a,t_regexp_instr_trade b   where a.fundid=b.fundid   and ( regexp_instr(a.seatid,replace(b.seatid,‘,‘,‘|‘))>0 or a.seatid is null ) ) where rid=1 ;

 

oracle11g的regexp函数

标签:--   over   null   tno   drop   一个   指定   ace   oracle11g   

原文地址:https://www.cnblogs.com/jiangqingfeng/p/8961615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!