Split one long comma string into multi column new table

前端 未结 3 1770
情书的邮戳
情书的邮戳 2021-01-27 12:14

I am newish to SQL to please excuse any ignorance. I have a table, called \'temp\' that contains one Field with one long comma seperated string, thus:

Field1
Ap         


        
3条回答
  •  醉话见心
    2021-01-27 12:58

    Oracle SQL:

    SELECT  REPLACE(SUBSTR(r_str, 1, INSTR(r_str, ',', 1, 1) - 1), ' ') AS r_substr_1
    ,       REPLACE(SUBSTR(r_str, INSTR(r_str, ',', 1, 1) + 1, INSTR(r_str, ',', 1, 2) - INSTR(r_str, ',', 1, 1) - 1), ' ') AS r_substr_2
    ,       REPLACE(SUBSTR(r_str, INSTR(r_str, ',', 1, 2) + 1, INSTR(r_str, ',', 1, 3) - INSTR(r_str, ',', 1, 2) - 1), ' ') AS r_substr_3
    ,       REPLACE(SUBSTR(r_str, INSTR(r_str, ',', 1, 3) + 1, INSTR(r_str, ',', 1, 4) - INSTR(r_str, ',', 1, 3) - 1), ' ') AS r_substr_4
    ,       REPLACE(SUBSTR(r_str, INSTR(r_str, ',', 1, 4) + 1), ' ')    AS r_substr_5
    FROM
    (
            SELECT  'Apples, oranges, pears,berries, melons' r_str FROM DUAL
    );
    
    Result: Apples  oranges pears   berries melons
    

提交回复
热议问题