Splitting Comma-Separated Values with SQLite's Common Table Expressions
Question:
How can I effortlessly split a comma-separated string in the Category column of a SQLite table? I seek a simpler approach than using Replace() and Trim() and avoid the limitations of substr().
Answer:
SQLite offers a feature called Common Table Expressions (CTEs) that allows for recursive queries, making it convenient to split comma-separated values.這是一個分解:
說明: ,用單個行包含一個空字符串和comma分離的字符串終止使用一個comma comma comma comma,'[umpur comma''
[[umpur)']查詢':WITH split(word, csv) AS ( SELECT '', 'Auto,A,1234444'||',' UNION ALL SELECT substr(csv, 0, instr(csv, ',')), substr(csv, instr(csv, ',') 1) FROM split WHERE csv != '' ) SELECT word FROM split WHERE word!='';從初始的空行和終端逗號過濾出來結果。
免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3