如何从sqlite3数据库中的字符串中删除字符?

Rah*_*yas 9 sqlite query-string

我有一个像这样的字符串a)我的sqlite数据库中的文本..我想要删除a)从数据库..任何人都知道这个查询?

Mar*_*off 12

@ laalto的答案很接近,但它不适用于边缘情况,特别是如果'a) '发生在字符串的其他地方.您只想SUBSTR删除前3个字符.

sqlite> SELECT REPLACE ("a) I have some information (or data) in the file.", "a) ", "");
I have some information (or datin the file.

sqlite> SELECT SUBSTR ("a) I have some information (or data) in the file.", 4);
I have some information (or data) in the file.
Run Code Online (Sandbox Code Playgroud)

所以更新他的查询,它应该变成:

UPDATE tbl SET col=SUBSTR(col, 4) WHERE col LIKE 'a) %';
Run Code Online (Sandbox Code Playgroud)

... 注意到SQLite中的字符串是从1索引的.


laa*_*lto 9

您还可以使用它REPLACE来删除字符串的一部分:

UPDATE tbl SET col=REPLACE(col, 'a) ', '') WHERE col LIKE 'a) %';
Run Code Online (Sandbox Code Playgroud)