我的网站的图片失效了,,,现在要把数据库表table中 body字段的图片地址全删掉 也就是从 “<img”到“ />”之间的部分。说明下<img 到/>中间是图片的地址,各个地址不同。

解决方案 »

  1.   

    为何不 SET URL  = NULL
      

  2.   


    update t set body = "<img />"
      

  3.   


    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 ,'')
      

  4.   

    select 
    stuff(col,charindex('<img',col),charindex('/>',col)-charindex('<img',col),'')
    from tb
    --看看是不是你要的结果
    --如果是再update
      

  5.   

    update tb set body =substring(body,1,charindex('<img',body))+
    substring(body,1+charindex('/>',body),len(body)-charindex('/>',body)) 
      

  6.   

    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
      

  7.   

    --> 测试数据: #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 行受影响)
      

  8.   

    #9楼的对了,但是我问题还没解决,我的是MYSQL,,,
    提示成功执行0个SQL语句!执行: update dede_addonarticle set body =substring(body,1,charindex('',body),len(body)-charindex('/>',body)) 出错,错误提示:FUNCTION root.charindex does not exist