登录  /  注册
除MSSQL数据库text字段中恶意脚本的删方法
php中文网
发布: 2016-06-07 17:58:34
原创
675人浏览过

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

方法很简单:text字段不能使用Replace,所以使用patindex
代码如下:
-select * from Product where P_Intro like '%%'
--text字段的替换处理示例--全表替换
-- select datalength(P_Intro),* from Product
--邀月 整理
--定义替换的字符串
declare @s_str nvarchar(4000),@d_str nvarchar(4000)
select @s_str='' --要替换的字符串
,@d_str='' --替换成的字符串


--因为只能用patindex,所以对于搜索字符串做处理
set @s_str='%'+@s_str+'%'

--定义游标,循环处理数据
declare @id bigint
declare #tb cursor for select P_ID from Product where P_Intro like '%%'
-- where P_ID=300727 ----where P_Intro like '%%'
open #tb
fetch next from #tb into @id
while @@fetch_status=0
begin
--字符串替换处理
declare @p varbinary(16)
,@p1 int,@p2 int
,@rplen int,@step int,@len int

select @p=textptr(P_Intro)
,@rplen=len(@s_str)-2
,@step=len(@d_str)
,@p1=patindex(@s_str,P_Intro)
,@len=datalength(P_Intro)
,@p2=0
from Product
where P_id=@id

while @p1>0
begin
set @p2=@p1+@p2-1
updatetext Product.P_Intro @p @p2 @rplen @d_str
select @p2=@p2+1,@p1=patindex(@s_str,substring(P_Intro,@p2+1,@len))
from Product where P_ID=@id
end
fetch next from #tb into @id
end
close #tb
deallocate #tb

--显示结果
---- select datalength(P_Intro),* from Product

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学