Split comma separated values to columns in Oracle

后端 未结 4 1651
温柔的废话
温柔的废话 2020-11-22 01:58

I have values being returned with 255 comma separated values. Is there an easy way to split those into columns without having 255 substr?

ROW  | VAL
--------         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 02:38

    You can use regexp_substr():

    select regexp_substr(val, '[^,]+', 1, 1) as val1, 
           regexp_substr(val, '[^,]+', 1, 2) as val2, 
           regexp_substr(val, '[^,]+', 1, 3) as val3, 
           . . .
    

    I would suggest that you generate a column of 255 numbers in Excel (or another spreadsheet), and use the spreadsheet to generate the SQL code.

提交回复
热议问题