当前位置:Gxlcms > 数据库问题 > Oracle 中使用正则表达式

Oracle 中使用正则表达式

时间:2021-07-01 10:21:17 帮助过:22人阅读

t3.cert_no from table_name t3 where regexp_like(t3.cert_no, ^(\d{15}|\d{18})$)

2。regexp_substr

SELECT REGEXP_SUBSTR(first field, second field , third field, , [^,]*,) FROM dual

3。regexp_instr

SELECT REGEXP_INSTR (hello itmyhome, e) FROM dual; 

4。regexp_replace

select regexp_replace(0123456789,01234,abc) from dual;

 拓展

1,通过证件号码获取生日

 select to_date(substr(110101200301010015,7,8),yyyyMMdd) from dual;

2,通过证件号码获取年龄

select trunc((to_char(sysdate, yyyyMMdd) -
             to_char(to_date(substr(110101200301010015, 7, 8),
                              yyyy-MM-dd),
                      yyyyMMdd)) / 10000)
  from dual;

3,通过证件号码获取年龄不满16周岁的生日(ps:证件号码为15位或者18位,今年为2019年16岁出生于20030101)

select to_date(substr(t.cert_no, 7, 8), yyyyMMdd)
  from table_name t
 where to_date((case when length(t.cert_no) = 18 then
                substr(t.cert_no, 7, 8) when length(t.cert_no) = 15 then
                19 || substr(t.cert_no, 7, 6) end),
               yyyyMMdd) < to_date(20030101, yyyyMMdd)

 

Oracle 中使用正则表达式

标签:正则表达式   case   har   正则   reg   to_date   ase   to_char   sele   

人气教程排行