Regexp oracle SQL



  • how can I check if string contains fixed number of numbers(int) then fixed number of characters and then again fixed numbers. I'm searching only for 9 numbers 2 latter's and then 4 numbers everything else is FALSE for me. From what I understand the best way to do it is with reg exp but can't set it up.



  • regexp_like might help.

    SQL> with test (col) as
      2    (select '123456789gm9876' from dual union all
      3     select '372737373ddd123' from dual
      4    )
      5  select
      6    col,
      7    case when regexp_like(col, '^[[:digit:]]{9}[[:alpha:]]{2}[[:digit:]]{4}$') then 'good'
      8         else 'bad'
      9    end result
     10  from test;
    

    COL RESULT


    123456789gm9876 good
    372737373ddd123 bad

    SQL>


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2