我有一个像这样的字符串a)我的sqlite数据库中的文本..我想从数据库中删除a)。任何人都知道这个查询?
答案 0 :(得分:11)
@ 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.
所以更新他的查询,它应该变成:
UPDATE tbl SET col=SUBSTR(col, 4) WHERE col LIKE 'a) %';
答案 1 :(得分:9)
您也可以使用REPLACE
删除字符串的一部分:
UPDATE tbl SET col=REPLACE(col, 'a) ', '') WHERE col LIKE 'a) %';
答案 2 :(得分:0)
我认为这段代码可以帮助您。
UPDATE TABLE_NAME SET COLUMN_NAME=REPLACE(COLUMN_NAME,'xxx','') WHERE COLUMN_NAME LIKE 'xxx%;
从上面的代码“ xxx”中删除不需要的字符串,当该字符串以xxx开头时,您要选择的列中的所有行均以xxx开头。