• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
西门吹雪
非我伤春春伤我,风一阵,雨一阵,好景不在哀残痕。 非我厌世世厌我,闲言来,碎语去,红颜憔悴心头冷。
博客园    首页    新随笔    联系   管理    订阅  订阅

MSSQL批量替换Text字符串

declare @old varchar(100)
declare @new varchar(100)
set @old='http://new.chaoren.com/CMS/localhost'
set @new='http://www.chaoren.com/CMS/localhost'
declare @ptr varbinary(16)
declare @newsid varchar(36)  --如为int则改为declare @newsid int
declare @Position int,@len int
set @len=datalength(@old)

declare yohen_Cursor scroll Cursor
for
select textptr([content]),[news_id] from t_news_content
where charindex(@old,content)>0 --and news_id='2007-06-08'
for read only

open yohen_Cursor
fetch next from yohen_Cursor into @ptr,@newsid
while @@fetch_status=0
begin
    select @Position=patindex('%' + @old + '%',[content]) from t_news_content where news_id=@newsid
    while @Position>0
    begin
    set @Position=@Position-1
    updatetext t_news_content.[content] @ptr @Position @len @new
    select @Position=patindex('%' + @old + '%',[content]) from t_news_content where news_id=@newsid
    end
    fetch next from yohen_Cursor into @ptr,@newsid
end
close yohen_Cursor
deallocate yohen_Cursor
go

经过网上搜索,可不是有错,就是结果没有反应。经过自己修改终于可以用了。放在此处供参考

posted @ 2007-09-10 11:55  西门吹雪  阅读(1128)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3