Split string by space and character as delimiter in Oracle with regexp_substr

前端 未结 5 2025
太阳男子
太阳男子 2020-12-04 00:32

I\'m trying to split a string with regexp_subtr, but i can\'t make it work.

So, first, i have this query

select regexp_substr(\'Helloworld - test!\'          


        
5条回答
  •  鱼传尺愫
    2020-12-04 01:00

    If i understood correctly, this will help you. Currently you are getting output as Helloworld(with space at the end). So i assume u don't want to have space at the end. If so you can simply use the space in the delimiter also like.

    select regexp_substr('Helloworld - test!' ,'[^ - ]+',1,1)from dual;
    
    OUTPUT
    Helloworld(No space at the end)
    

    As u mentioned in ur comment if u want two columns output with Helloworld and test!. you can do the following.

    select regexp_substr('Helloworld - test!' ,'[^ - ]+',1,1),
           regexp_substr('Helloworld - test!' ,'[^ - ]+',1,3) from dual;
    
    OUTPUT
    col1         col2
    Helloworld   test!
    

提交回复
热议问题