Join to splitted string columns in Oracle

后端 未结 3 977
南笙
南笙 2021-01-28 06:40

I have a column in our database that holds 4 fields as a \"\\\" delimited string.

I have split the fields as I need them seperatly in my report.

I also need to

3条回答
  •  离开以前
    2021-01-28 07:39

    WARNING! The regular expression '[^\]+' will return unexpected results if there is a null item in the list and you are selecting the element after that null item. See this example where the 3rd item is selected, but '4' is returned. '4' is really the 4th item in the delimited list, not the third. Indeed it is the 3rd item where there is a value though.

    SQL> select REGEXP_SUBSTR('1\\3\4', '[^\]+', 1, 3) colA from dual;
    
    C
    -
    4
    
    SQL>
    

    Use this instead, where the actual 3rd item in the list is selected:

    SQL> select REGEXP_SUBSTR('1\\3\4', '([^\]*)(\\|$)', 1, 3, NULL, 1) colA from dual;
    
    C
    -
    3
    

    See this post for a more detailed example and explanation: REGEX to select nth value from a list, allowing for nulls

提交回复
热议问题