国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > SQL Server > 正文

除MSSQL數據庫text字段中惡意腳本的刪方法

2024-08-31 00:59:17
字體:
來源:轉載
供稿:網友
方法很簡單:text字段不能使用Replace,所以使用patindex

復制代碼 代碼如下:


-select * from Product where P_Intro like '%<script src="http://my.stsw518.cn/a002/1.js" src="http://my.stsw518.cn/a002/1.js"></script>%'
--text字段的替換處理示例--全表替換
-- select datalength(P_Intro),* from Product
--邀月 整理
--定義替換的字符串
declare @s_str nvarchar(4000),@d_str nvarchar(4000)
select @s_str='<script src="http://my.stsw518.cn/a002/1.js" src="http://my.stsw518.cn/a002/1.js"></script>' --要替換的字符串
,@d_str='' --替換成的字符串


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

--定義游標,循環處理數據
declare @id bigint
declare #tb cursor for select P_ID from Product where P_Intro like '%<script src="http://my.stsw518.cn/a002/1.js" src="http://my.stsw518.cn/a002/1.js"></script>%'
-- where P_ID=300727 ----where P_Intro like '%<script src="http://my.stsw518.cn/a002/1.js" src="http://my.stsw518.cn/a002/1.js"></script>%'
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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西和县| 北票市| 潮州市| 宁夏| 双鸭山市| 连南| 富源县| 绩溪县| 内乡县| 于都县| 维西| 建瓯市| 家居| 沙田区| 扎兰屯市| 苏尼特右旗| 盐山县| 温泉县| 石阡县| 嵊泗县| 土默特左旗| 南宫市| 磐石市| 岚皋县| 井冈山市| 吉首市| 杭锦旗| 仁寿县| 青田县| 襄城县| 濮阳县| 封丘县| 尉氏县| 通道| 华阴市| 西林县| 交口县| 永清县| 青神县| 腾冲县| 仪陇县|