Oracle 中使用正则表达式

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

1。regexp_like 

select 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')
原文地址:https://www.cnblogs.com/yinyl/p/11263353.html