Split a string into rows using pure SQLite

前端 未结 4 1424
深忆病人
深忆病人 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:27

    This is possible with a recursive common table expression:

    WITH RECURSIVE split(s, last, rest) AS (
      VALUES('', '', 'C:\Users\fidel\Desktop\Temp')
      UNION ALL
      SELECT s || substr(rest, 1, 1),
             substr(rest, 1, 1),
             substr(rest, 2)
      FROM split
      WHERE rest <> ''
    )
    SELECT s
    FROM split
    WHERE rest = ''
       OR last = '\';
    

    (You did not ask for a reasonable way.)

提交回复
热议问题