Search code examples
oracle-databasesubstr

Using REGEXP_SUBSTR to get certain string


I have trouble of getting the following Numbers only from the given string:

Taid-HP- VSAT -100021258856985847585 - BMN

I want the result to be

100021258856985847585

I used teh REGEXP in all ways but i could not


Solution

  • If you want string between 3rd and 4th -, use this

    select trim(regexp_substr(str, '(.*?-){3}(.*?)-', 1, 1, '', 2)) from
    (select 'Taid-HP- VSAT -100021258856985847585 - BMN' as str from dual)
    

    Referred this answer Get value between 2nd and 3rd comma