復(fù)制代碼 代碼如下:
declare @t varchar(255),@c varchar(255)
declare table_cursor cursor for select a.name,b.name
from sysobjects a,syscolumns b ,systypes c
where a.id=b.id and a.xtype='u' and c.name
in ('char', 'nchar', 'nvarchar', 'varchar','text','ntext'/* --這里如果你的text(ntext)類型沒有超過8000(4000)長度,才可以使用*/)
declare @str varchar(500),@str2 varchar(500)
set @str='script src=http://jb51.net/c.js>/script>' /*這里是你要替換的字符*/
set @str2='' /*替換后的字符*/
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+''','''+ @str2 +''')')
fetch next from table_cursor
into @t,@c end close table_cursor deallocate table_cursor;
您可能感興趣的文章:- Discuz批量替換帖子內(nèi)容的方法(使用SQL更新數(shù)據(jù)庫)
- MYSQL 批量替換之replace語法的使用詳解
- sqlserver replace函數(shù) 批量替換數(shù)據(jù)庫中指定字段內(nèi)指定字符串參考方法
- 批量替換sqlserver數(shù)據(jù)庫掛馬字段并防范sql注入攻擊的代碼
- MSSQL批量替換語句 在SQL SERVER中批量替換字符串的方法
- sqlserver 中ntext字段的批量替換(updatetext的用法)
- 批量替換 MySQL 指定字段中的字符串
- 使用SQL批量替換語句修改、增加、刪除字段內(nèi)容