zoukankan      html  css  js  c++  java
  • 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 ;

  • 相关阅读:
    .net Core使用EFCore连接数据库
    前端实践项目(二)webpack生成html和外部引用
    前端实践项目(一)使用webpack进行打包编译
    消息队列的模式
    消息队列的应用场景
    .Net EasyNetQ的使用
    .Net中简单地使用RabbitMQ消息队列
    C# 虚函数virtual的使用之二
    C#之System.Object
    .Net EntityFramework(EF) CodeFirst模式
  • 原文地址:https://www.cnblogs.com/jiangqingfeng/p/8961615.html
Copyright © 2011-2022 走看看