假设您在表中存储了以下内容:
{2:22} {4:5} {34:4}
我将从该字符串中删除{4:5}的内容,但是系统剂量知道“:”后的数字只是第一个。查询看起来像这样:
更新tbl
SET this
= REPLACE(this
,'{4:??}','')WHERE id
= 1;
我需要放入什么?返回以下结果的地方?
{2:22} {34:4}
最佳答案
这是使用LEFT
,SUBSTRING
,LOCATE
和REPLACE
的一种方法:
update yourtable
set yourcolumn =
replace(yourcolumn,
Left(
Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)),
Locate('}',Substring(yourcolumn,
Locate('{4:',yourcolumn),
Length(yourcolumn)))),
'')
SQL Fiddle Demo