How to split comma-separated value in SQLite?

前端 未结 5 536

I want to split comma-separated String inside SQLite database

Example: I have a Category column in 1 of my table.

|Category         


        
5条回答
  •  借酒劲吻你
    2020-12-01 17:29

    You can use a common table expression to split comma separated values in SQLite.

    WITH split(word, str) AS (
        -- alternatively put your query here
        -- SELECT '', category||',' FROM categories
        SELECT '', 'Auto,A,1234444'||','
        UNION ALL SELECT
        substr(str, 0, instr(str, ',')),
        substr(str, instr(str, ',')+1)
        FROM split WHERE str!=''
    ) SELECT word FROM split WHERE word!='';
    

    Output is as expected:

    Auto
    A
    1234444
    

提交回复
热议问题