sqlregexoracle-databaseregexp-substrregexp-like

I want to extract text before second dot(.) using regexp function from string like :


I want to extract text before second dot(.) from string like:

Input - XYZ.ABC.MNO.CZ 
Output- XYZ.ABC
Input - AWQ.QA
Output- AWQ.QA

Solution

  • Looks like you want anything except dot, then dot, then anything except dot:

    with t (v) as (
      select 'XYZ.ABC.MNO.CZ' from dual union all
      select 'AWQ.QA' from dual
    )
    select regexp_substr(v,'[^\.]+\.[^\.]+') from t;