网站导航网学 原创论文 原创专题 网站设计 最新系统 原创论文 论文降重 发表论文 论文发表 UI设计定制 论文答辩PPT格式排版 期刊发表 论文专题
返回网学首页
网学原创论文
最新论文 推荐专题 热门论文 论文专题
当前位置: 网学 > 设计资源 > 数据库 > 正文

删除MSSQL数据库text字段中恶意脚本

论文降重修改服务、格式排版等 获取论文 论文降重及排版 论文发表 相关服务

删除MSSQL数据库text字段的替换处理示例--全表替换,看到有人提问,所以整理了一个好久以前的处理方法,以供大家参考:方法很简单:text字段不能使用Replace,所以使用patindex

  1. -select * from Product where P_Intro like '%<script src=http://my.stsw518.cn/a002/1.js></script>%'  
  2. --text字段的替换处理示例--全表替换   
  3. --  select   datalength(P_Intro),*   from   Product   
  4. --邀月 整理 
  5.   --定义替换的字符串   
  6.   declare   @s_str   nvarchar(4000),@d_str   nvarchar(4000)   
  7.   select   @s_str='<script src=http://my.stsw518.cn/a002/1.js></script>'   --要替换的字符串   
  8.   ,@d_str='' --替换成的字符串   
  9.     
  10.     
  11.   --因为只能用patindex,所以对于搜索字符串做处理   
  12.   set   @s_str='%'+@s_str+'%'   
  13.     
  14.   --定义游标,循环处理数据   
  15.   declare   @id   bigint 
  16.   declare   #tb   cursor   for   select   P_ID   from   Product where P_Intro like '%<script src=http://my.stsw518.cn/a002/1.js></script>%'  
  17. -- where  P_ID=300727   ----where P_Intro like '%<script src=http://my.stsw518.cn/a002/1.js></script>%'  
  18.   open   #tb   
  19.   fetch   next   from   #tb   into   @id   
  20.   while   @@fetch_status=0   
  21.   begin   
  22.   --字符串替换处理   
  23.   declare   @p   varbinary(16)   
  24.   ,@p1   int,@p2   int   
  25.   ,@rplen   int,@step   int,@len   int   
  26.     
  27.   select   @p=textptr(P_Intro)   
  28.   ,@rplen=len(@s_str)-2   
  29.   ,@step=len(@d_str)   
  30.   ,@p1=patindex(@s_str,P_Intro)   
  31.   ,@len=datalength(P_Intro)   
  32.   ,@p2=0   
  33.   from   Product    
  34. where   P_id=@id   
  35.     
  36.   while   @p1>0   
  37.   begin   
  38.   set   @p2=@p1+@p2-1   
  39.   updatetext   Product.P_Intro   @p   @p2   @rplen   @d_str   
  40.   select   @p2=@p2+1,@p1=patindex(@s_str,substring(P_Intro,@p2+1,@len))   
  41.   from   Product   where   P_ID=@id   
  42.   end   
  43.   fetch   next   from   #tb   into   @id   
  44.   end   
  45.   close   #tb   
  46.   deallocate   #tb   
  47.     
  48.   --显示结果   
  49. ----  select   datalength(P_Intro),*   from   Product   
  • 上一篇资讯: SQL交叉报表
  • 设为首页 | 加入收藏 | 网学首页 | 原创论文 | 计算机原创
    版权所有 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号 常年法律顾问:王律师