Split a string into rows using pure SQLite

前端 未结 4 1423
深忆病人
深忆病人 2020-12-16 06:08

Using SQLite, I\'d like to split a string in the following way.

Input string:

C:\\Users\\fidel\\Desktop\\Temp

and have

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 06:16

    If you want to search for the values ​​individually, use the code below:

    WITH RECURSIVE split(content, last, rest) AS (
    VALUES('', '', 'value1§value2§value3§value4§value5§value6§value7')
    UNION ALL
      SELECT 
    
        CASE WHEN last = '§' 
                THEN
                    substr(rest, 1, 1)
                ELSE
                    content || substr(rest, 1, 1)
        END,
         substr(rest, 1, 1),
         substr(rest, 2)
      FROM split
      WHERE rest <> ''
    )
    SELECT 
           REPLACE(content, '§','') AS 'ValueSplit'     
    FROM 
           split
    WHERE 
           last = '§' OR rest ='';
    

    Result:

    **ValueSplit**
    
    value1
    value2
    value3
    value4
    value5
    value6
    value7
    

    I hope I can help people with the same problem.

提交回复
热议问题