zoukankan      html  css  js  c++  java
  • SQL text字段的替换处理(无法批量更新,写法记录)

    注: SQL2005以上版本直接使用varchar(max)的replace即可

    此处只是记录一种写法

    /*--text字段的替换处理 
    --
    */ 
    --创建数据测试环境 
    create   table   #tb(aa   text
    insert   into   #tb   
    select   'abc123abc123,asd ' 

    --定义替换的字符串 
    declare   @s_str   varchar(8000),@d_str   varchar(8000
    select   @s_str= '123 '   --要替换的字符串 
    ,@d_str= '000 ' --替换成的字符串 

    --字符串替换处理 
    declare   @p   varbinary(16),@postion   int,@rplen   int 
    select   @p=textptr(aa),@rplen=len(@s_str),@postion=charindex(@s_str,aa)-1   from   #tb 
    while   @postion> 0 
    begin 
    updatetext   #tb.aa   @p   @postion   @rplen   @d_str 
    select   @postion=charindex(@s_str,aa)-1   from   #tb 
    end 

    --显示结果 
    select   *   from   #tb 

    --删除数据测试环境 
    drop   table   #tb 
  • 相关阅读:
    php第九节课
    php第八节课
    php第七节课
    php第六讲
    php第五节课
    php第四节课
    php第三节课
    Golang Slice切片
    Golang 反射
    Golang 流程控制
  • 原文地址:https://www.cnblogs.com/hejunrex/p/2468823.html
Copyright © 2011-2022 走看看