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