我在sqlite数据库中有一个我需要修改的列。
该列是一个值数组,如下所示:
0.021460.04419,0.04551,0.02734,0.011,0.005
数组缺少第一个和第二个值之间的逗号,因此数组应如下所示:
0.02146,0.04419,0.04551,0.02734,0.011,0.005
数据值永远不会大于0.9,所以我试图构建一个更新查询,它将使用replace()函数执行字符串替换,识别第二个“0”。并将其替换为“,0。”,但我不知道该怎么做。
答案 0 :(得分:6)
只需为{em>所有次0.
次出现添加逗号:
replace(TheColumn, '0.', ',0.')
然后删除重复项:
replace(replace(TheColumn, '0.', ',0.'), ',,', ',')
和开头的逗号:
substr(replace(replace(TheColumn, '0.', ',0.'), ',,', ','), 2)