목차

REGEXP_LIKE

정의

  1. 오라클 정규표현식의 하나.

이메일 형식 체크

  1. 이메일 형식 체크(Validate)이 맞는지 확인하는 쿼리이다.
    select email 
    from member 
    where regexp_like(email,'[^ ]+@[^.][^ ]+\..[^ ]+');
  2. 이메일 형식체크에 quotes 를 포함하여 아래의 구문을 따른다.
    '[a-zA-Z0-9._%-]+@[a-zA-Z0-9._%-]+\.[a-zA-Z]{2,4}' 


    http://stackoverflow.com/questions/787167/validation-on-email-postcode-fields-in-sql-oracle

날짜형식 체크

  1. 날짜형식 체크
    ALTER SESSION SET NLS_LANGUAGE='AMERICAN';
    with t as (
      select '01-02-2007' str from dual union all
      select '7-8-2007'   str from dual union all
      select '2007/03/28' str from dual union all
      select '10-MAY-07'  str from dual
    )
    select str
      , to_date(str, case when regexp_like(str,'[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}')
                               then 'dd-mm-yyyy'
                          when regexp_like(str,'[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}')
                               then 'yyyy/mm/dd'
                          when regexp_like(str,'[0-9]{2}-[A-Z]{3}-[0-9]{2}')
                               then 'dd-mon-yy'
                     end) as date1
    from t;


    ORA-01843: not a valid month 가 나올경우 NLS_LANG 을 확인해 본다.

    with t as (
      select '01-02-2007' str from dual union all
      select '7-8-2007'   str from dual union all
      select '2007/03/28' str from dual union all
      select '10-MAY-07'  str from dual
    )
    select str
      , to_date(str, case when regexp_like(str,'[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}')
                               then 'dd-mm-yyyy'
                          when regexp_like(str,'[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}')
                               then 'yyyy/mm/dd'
                          when regexp_like(str,'[0-9]{2}-[A-Z]{3}-[0-9]{2}')
                               then 'dd-mon-yy'
                     end,'NLS_DATE_LANGUAGE=AMERICAN') as date1
    from t;