How to get string after character oracle

后端 未结 2 1722
暗喜
暗喜 2020-12-10 12:50

I have VP3 - Art & Design and HS5 - Health & Social Care, I need to get string after \'-\' in Oracle. Can this be achieved using substring?

2条回答
  •  一个人的身影
    2020-12-10 13:01

    You can use regexp_substr():

    select regexp_substr(col, '[^-]+', 1, 2)
    

    If you want to remove an optional space, then you can use trim():

    select trim(leading ' ', regexp_substr(col, '[^-]+', 1, 2))
    

    The non-ovious parameters mean

    • 1 -- search from the first character of the source. 1 is the default, but you have to set it anyway to be able to provide the second parameter.
    • 2 -- take the second match as the result substring. the default would be 1.

提交回复
热议问题