SQLite - replace part of a string

后端 未结 3 1678
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 13:34

Is it possible using SQL in an SQLite table to replace part of a string?

For example, I have a table where one of the fields holds the path

3条回答
  •  萌比男神i
    2020-12-07 14:27

    @Andrew answer is partially correct. No need to use WHERE clause here:

    1. Only fields containing C:\afolder will be affected anyway, no reason to check it. It's excessive.
    2. 'C:\afolder\%' will choose only fields starting with C:\afolder\ only. What if you have this path inside string?

    So the correct query is just:

    UPDATE table SET field = replace( field, 'C:\afolder\', 'C:\anewfolder\');
    

提交回复
热议问题