如上面的内容。。我这样替换
update bbs_announce set content=replace(content,'\]UploadFile/','\]UploadFile_20031/') where announce_id = 1 escape '\'
不知道哪里出错了?
update bbs_announce set content=replace(content,'\]UploadFile/','\]UploadFile_20031/') where announce_id = 1 escape '\'
不知道哪里出错了?
SELECT @pos=PATINDEX('%\]UploadFile/%', content)
FROM bbs_announce
WHERE announce_id = 1 escape '\'
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'
GO
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(content)
FROM bbs_announce
WHERE announce_id=1
UPDATETEXT bbs_announce.content @ptrval @pos 12 ']uploadfile_20041/'
GO
EXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'
go
where announce_id =1
试一下
create table test(id varchar(3),txt text)
insert into test
select '001',REPLICATE('a',4000) + REPLICATE('b',2000) + REPLICATE('ab',2000)
union all select '002',REPLICATE('a',4000) + REPLICATE('b',2000) + REPLICATE('ab',2000)
go
--定义替换的字符串
declare @s_str varchar(8000),@d_str varchar(8000),@id varchar(3)
select @id='001' --要替换的记录id
,@s_str='a' --要替换的字符串
,@d_str='ab' --替换成的字符串
--因为只能用patindex,所以对于搜索字符串做处理
set @s_str='%'+@s_str+'%'--字符串替换处理
declare @p varbinary(16)
,@p1 int,@p2 int
,@rplen int,@step int,@len intselect @p=textptr(txt)
,@rplen=len(@s_str)-2
,@step=len(@d_str)
,@p1=patindex(@s_str,txt)
,@len=datalength(txt)
,@p2=0
from test where id=@id
while @p1>0
begin
set @p2=@p1+@p2-1
updatetext test.txt @p @p2 @rplen @d_str
select @p2=@p2+1,@p1=patindex(@s_str,substring(txt,@p2+1,@len))
from test where id=@id
end--显示结果
select datalength(txt),* from testgo
--删除数据测试环境
drop table test