批量替换ntext字段内容,@textA为要替换的字符串,@textB为替换后的字符串

简介: 代码 --批量替换ntext字段内容,@textA为要替换的字符串,@textB为替换后的字符串--exec P_replace_TableNTEXT 'B_Goods','G_Content','GID','61.
代码
-- 批量替换ntext字段内容,@textA为要替换的字符串,@textB为替换后的字符串
--
exec P_replace_TableNTEXT 'B_Goods','G_Content','GID','61.152.93.172:888','212.95.33.47'
create proc P_replace_TableNTEXT
(
@tableName varchar ( 50 ),
@ColNTEXT varchar ( 50 ),
@ColPrimaryKey varchar ( 50 ),
@textA nvarchar ( 500 ),
@textB nvarchar ( 500 )
)
as
exec ( '
declare @str varbinary(16),@id int,@position int,@len int
set @len = datalength(
''' + @textA + ''' )
declare cursor_replace scroll Cursor
for select textptr(
' + @ColNTEXT + ' ), ' + @ColPrimaryKey + ' from ' + @tableName + '
for read only
open cursor_replace
fetch next from cursor_replace into @str,@id
while @@fetch_status=0
begin
select @position=patindex(
'' % ' + @textA + ' % '' , ' + @ColNTEXT + ' ) from ' + @tableName + ' where ' + @ColPrimaryKey + ' =@id
while @position>0
begin
set @position=@position-1
updatetext
' + @tableName + ' . ' + @ColNTEXT + ' @str @position @len ''' + @textB + '''
select @position=patindex(
'' % ' + @textA + ' % '' , ' + @ColNTEXT + ' ) from ' + @tableName + ' where ' + @ColPrimaryKey + ' =@id
end
fetch next from cursor_replace into @str,@id
end
close cursor_replace
deallocate cursor_replace
' )
go
目录
相关文章
|
2月前
|
索引 Python
字符串:比较、拼接、切割、转义字符;相关切割、替换、查找、去除空白、转大小写函数的方法
字符串:比较、拼接、切割、转义字符;相关切割、替换、查找、去除空白、转大小写函数的方法
19 0
|
12月前
|
Shell Perl
把一个文档前五行中包含字母的行删掉,同时删除6到10行包含的所有字母
把一个文档前五行中包含字母的行删掉,同时删除6到10行包含的所有字母
96 1
|
数据安全/隐私保护 索引
labview字符串数据长度连接子字符串大小写替换删除插入日期匹配
labview字符串数据长度连接子字符串大小写替换删除插入日期匹配
165 0
|
索引
查询字符串 & 模板字符串
查询字符串 & 模板字符串
|
存储 安全 前端开发
Go-字符和字符串类型详解(原始字符串、拼接、修改、比较、拆分、查找等)
Go-字符和字符串类型详解(原始字符串、拼接、修改、比较、拆分、查找等)
126 0
Go-字符和字符串类型详解(原始字符串、拼接、修改、比较、拆分、查找等)
用#替换字符
给定一个由大小写字母构成的字符串。 把该字符串中特定的字符全部用字符 # 替换。
102 0
替换 &开头。;结尾之间的内容。用空格代替他们
替换 &开头。;结尾之间的内容。用空格代替他们
|
关系型数据库 MySQL PHP
MYSQL表中某个字段有换行符、回车符替换成空字符串
mysql某个字段,带引号查不出来,不带引号却可以查出来,有可能就是因为这个字段有换行或者回车符
539 0
MYSQL表中某个字段有换行符、回车符替换成空字符串
正则匹配指定字符之间的内容,并替换(多个匹配替换)
var str="是吗@Test1:我觉得你说的很对@Test:学无止境"; var r=str.match(/@.*?:/ig); for (var index = 0; index < r.
2393 0