在 SQLite 中拆分字符串

Splitting strings in SQLite

有谁知道如何拆分我的地址列。我想把它分成三个新的列,用逗号分隔。 例如1808 FOX CHASE DR, GOODLETTSVILLE, TN分为

到目前为止我已经试过了

SELECT SUBSTRING(OwnerAddress, 1, INSTR(OwnerAddress, ',')-1) as col1,
SUBSTRING(OwnerAddress, INSTR(OwnerAddress, ',')+1) as col2  
FROM housing_data;

虽然我无法创建带有州缩写的第三列。

感谢任何意见

在目标库中进行任何类型的字符串处理通常要干净得多。也就是说,如果必须,您可以自由使用 SUBSTRINGINSTR 来查找每个逗号并拆分字符串:

SELECT 
    SUBSTRING(OwnerAddress, 1, INSTR(OwnerAddress, ',') - 1) as col1,
    SUBSTRING(SUBSTRING(OwnerAddress, INSTR(OwnerAddress, ',') + 1), 1, INSTR(SUBSTRING(OwnerAddress, INSTR(OwnerAddress, ',') + 1), ',') - 1) as col2,
    SUBSTRING(SUBSTRING(OwnerAddress, INSTR(OwnerAddress, ',') + 1), INSTR(SUBSTRING(OwnerAddress, INSTR(OwnerAddress, ',') + 1), ',') + 1) as col3
FROM housing_data;