while exists(select 1 from tb where charindex('<img',body)>0) update tb set body=stuff(body,charindex('<img',body)+1, charindex('/>',body,charindex('<img',body)+1)-charindex('<img',body)- 4 ,'')
select stuff(col,charindex('<img',col),charindex('/>',col)-charindex('<img',col),'') from tb --看看是不是你要的结果 --如果是再update
update tb set body =substring(body,1,charindex('<img',body))+ substring(body,1+charindex('/>',body),len(body)-charindex('/>',body))
3楼 BODY中还有其他文字内容 你这样不行的 4楼 我运行得到了这个,请再帮我看下成功执行0个SQL语句! 执行: while exists(select body from dede_addonarticle where charindex('0) update dede_addonarticle set body=stuff(body,charindex('',body,charindex(' 出错,错误提示:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while exists(select body from dede_addonarticle where charindex('0) ' at line 1
--> 测试数据: #tb if object_id('tempdb.dbo.#tb') is not null drop table #tb go create table #tb (body varchar(115)) insert into #tb select 'gwe<imgfa333sfa/>33' union all select '2<imgfae55esfa/>3134' union all select '31<imgffsasfa/>3'update #tb set body =substring(body,1,charindex('<img',body)-1)+ substring(body,2+charindex('/>',body),len(body)-charindex('/>',body)) select * from #tbbody ------------------------------------------------------------------------------------------------------------------- gwe33 23134 313(3 行受影响)
#9楼的对了,但是我问题还没解决,我的是MYSQL,,, 提示成功执行0个SQL语句!执行: update dede_addonarticle set body =substring(body,1,charindex('',body),len(body)-charindex('/>',body)) 出错,错误提示:FUNCTION root.charindex does not exist
update t set body = "<img />"
while exists(select 1 from tb where charindex('<img',body)>0)
update tb set body=stuff(body,charindex('<img',body)+1, charindex('/>',body,charindex('<img',body)+1)-charindex('<img',body)- 4 ,'')
stuff(col,charindex('<img',col),charindex('/>',col)-charindex('<img',col),'')
from tb
--看看是不是你要的结果
--如果是再update
substring(body,1+charindex('/>',body),len(body)-charindex('/>',body))
4楼 我运行得到了这个,请再帮我看下成功执行0个SQL语句!
执行: while exists(select body from dede_addonarticle where charindex('0) update dede_addonarticle set body=stuff(body,charindex('',body,charindex(' 出错,错误提示:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'while exists(select body from dede_addonarticle where charindex('0) ' at line 1
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb (body varchar(115))
insert into #tb
select 'gwe<imgfa333sfa/>33' union all
select '2<imgfae55esfa/>3134' union all
select '31<imgffsasfa/>3'update #tb set body =substring(body,1,charindex('<img',body)-1)+
substring(body,2+charindex('/>',body),len(body)-charindex('/>',body)) select * from #tbbody
-------------------------------------------------------------------------------------------------------------------
gwe33
23134
313(3 行受影响)
提示成功执行0个SQL语句!执行: update dede_addonarticle set body =substring(body,1,charindex('',body),len(body)-charindex('/>',body)) 出错,错误提示:FUNCTION root.charindex does not exist