请教高手,关于updatetext修改表的用法。

netspies 2006-08-25 07:12:12
有一个表T(ID,Context),其中Context为text类型,我想把里面的‘abccs'全部替换成‘11011',请问怎么实现。
...全文
294 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
netspies 2006-08-28
  • 打赏
  • 举报
回复
Declare @s_str varchar(8000), @d_str varchar(8000)
Select @s_str='abccs' , --要替换的字符串
@d_str='11011' --替换成的字符串

Declare @p varbinary(16),@postion int,@rplen int
Select @p=textptr(Context),@rplen=len(@s_str),@postion=charindex(@s_str,Context)-1 from tb
while @postion >= 0 -------------------------------修改地方------
begin
updatetext tb.Context @p @postion @rplen @d_str
select @postion=charindex(@s_str,Context)-1 from tb
end
netspies 2006-08-27
  • 打赏
  • 举报
回复
就没有人作过么?

邹建 老大呢!
netspies 2006-08-26
  • 打赏
  • 举报
回复
--如果长度大于8000,用如下语句

Declare @s_str varchar(8000), @d_str varchar(8000)
Select @s_str='abccs' , --要替换的字符串
@d_str='11011' --替换成的字符串

Declare @p varbinary(16),@postion int,@rplen int
Select @p=textptr(Context),@rplen=len(@s_str),@postion=charindex(@s_str,Context)-1 from tb
while @postion>0
begin
updatetext tb.Context @p @postion @rplen @d_str
select @postion=charindex(@s_str,Context)-1 from tb
end

===================================================================
这段不执行,但是没有语法错误,不知道原因,请指教.
wisdomone 2006-08-26
  • 打赏
  • 举报
回复
up
WangZWang 2006-08-25
  • 打赏
  • 举报
回复
--如果长度大于8000,用如下语句

Declare @s_str varchar(8000), @d_str varchar(8000)
Select @s_str='abccs' , --要替换的字符串
@d_str='11011' --替换成的字符串

Declare @p varbinary(16),@postion int,@rplen int
Select @p=textptr(Context),@rplen=len(@s_str),@postion=charindex(@s_str,Context)-1 from tb
while @postion>0
begin
updatetext tb.Context @p @postion @rplen @d_str
select @postion=charindex(@s_str,Context)-1 from tb
end
WangZWang 2006-08-25
  • 打赏
  • 举报
回复
--如果长度小于8000
update tb set Context=replace(cast(Context as varchar),'abccs','11011')

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧