身份证验证正则表达式oracle,在Oracle中使用正则表达式

Oracle使用正则表达式离不开这4个函数

1。regexp_like

2。regexp_substr

3。regexp_instr

4。regexp_replace

看函数名称大概就能猜到有什么用了。

regexp_like 只能用于条件表达式,和 like 类似,但是使用的正则表达式进行匹配,语法很简单

regexp_substr 函数,和 substr 类似,用于拾取合符正则表达式描述的字符子串,语法如下

regexp_instr 函数,和 instr 类似,用于标定符合正则表达式的字符子串的开始位置,语法如下

regexp_replace 函数,和 replace 类似,用于替换符合正则表达式的字符串,语法如下

这里解析一下几个参数的含义

1。source_char,输入的字符串,可以是列名或者字符串常量、变量。

2。pattern,正则表达式。

3。match_parameter,匹配选项。

取值范围: i:大小写不敏感; c:大小写敏感;n:点号 . 不匹配换行符号;m:多行模式;x:扩展模式,忽略正则表达式中的空白字符。

4。position,标识从第几个字符开始正则表达式匹配。

5。occurrence,标识第几个匹配组。

6。replace_string,替换的字符串。

说了一堆文绉绉的,现在开始实例演练了,在此之前先建好一个表。

01 create table tmp as

02 with data as (

03   select ‘like‘ as id ,‘a9999‘ as str from dual union all

04   select ‘like‘   ,‘a9c‘     from dual union all

05   select ‘like‘   ,‘A7007‘    from dual union all

06   select ‘like‘   ,‘123a34cc‘   from dual union all

07   select ‘substr‘   ,‘123,234,345‘  from dual union all

08   select ‘substr‘   ,‘12,34.56:78‘  from dual union all

09   select ‘substr‘   ,‘123456789‘   from dual union all

10   select ‘instr‘   ,‘192.168.0.1‘  from dual union all

11   select ‘replace‘   ,‘(020)12345678‘ from dual union all

12   select ‘replace‘   ,‘001517729C28‘ from dual

13 )

14 select * from data ;

15

16 select * from tmp ;

17 ID   STR

18 ------- -------------

19 like   a9999

20 like   a9c

21 like   A7007

22 like   123a34cc

23 substr  123,234,345

24 substr  12,34.56:78

25 substr  123456789

26 instr   192.168.0.1

27 replace (020)12345678

28 replace 001517729C28

regexp_like 例子

01 select str from tmp where id=‘like‘ and regexp_like(str,‘A“d+‘,‘i‘); -- ‘i‘ 忽略大小写

02 STR

03 -------------

04 a9999

05 a9c

06 A7007

07 123a34cc

08

09 select str from tmp where id=‘like‘ and regexp_like(str, ‘a“d+‘);

10 STR

11 -------------

12 a9999

13 a9c

14 123a34cc

15

16 select str from tmp where id=‘like‘ and regexp_like(str,‘^a“d+‘);

17 STR

18 -------------

19 a9999

20 a9c

21

22 select str from tmp where id=‘like‘ and regexp_like(str,‘^a“d+$‘);

23 STR

24 -------------

25 a9999

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值