• oracle11g的regexp函数


    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 ;

  • 相关阅读:
    alpha冲刺9
    alpha冲刺8
    alpha冲刺7
    alpha冲6
    随堂小测-同学录
    alpha冲刺5
    任务3
    任务2
    任务1
    网站用户行为分析
  • 原文地址:https://www.cnblogs.com/jiangqingfeng/p/8961615.html
Copyright © 2020-2023  润新知