update 表 set 地区=replace(地区,'中国','中华人民共和国')

解决方案 »

  1.   

    update 表 set 地区=replace(地区,'中国','中华人民共和国')
      

  2.   

    update 表 set 地区=replace(地区,'中国','中华人民共和国')
      

  3.   

    --或者加上条件,只处理符合要求的记录:update 表 set 地区=replace(地区,'中国','中华人民共和国')
    where 地区 like '%中国%'
      

  4.   

    怎么有错误?
    argument data type ntext is invalid from argument 1 of replace function
    这是怎么回事??
      

  5.   

    create table test(id int identity(1,1),content text)
    insert test values('asdfsdfasdfsadfsdjflk大力sdjflkasjdf;lasdjf;lafsd')
    insert test values('fdsgdsfgdfgsdfghrtjtyjkhkhjkhjljk大力ljk;jk;kl;kl;kl;')
    gocreate proc 替换
    @s_str varchar(100),
    @d_str varchar(100)
    as
    declare @id int
    declare #tb cursor for select id from test
    open #tb
    fetch next from #tb into @id
    while @@fetch_status=0
    begin
      declare @p varbinary(16),@postion int,@rplen int
      select @p=textptr(CONTENT),@rplen=len(@s_str),@postion=charindex(@s_str,CONTENT)-1 from test where id=@id
      while @postion>0
        begin
          updatetext test.CONTENT @p @postion @rplen @d_str
            select @postion=charindex(@s_str,content)-1 from test where id=@id
        end
      fetch next from #tb into @id
    end
    close #tb
    deallocate #tb
    goexec 替换 '大力','AAAAA'goselect * from testgo
    drop table test
      

  6.   

    怎么有错误?
    argument data type ntext is invalid from argument 1 of replace function
    这是怎么回事??你是ntext类型的字符串,不能直接用replace函数替换
      

  7.   

    ntext类型的字符串不能用上面的处理方法,改用:create table hello(id int identity(1,1),CONTENT text)
    insert into hello
    select '<IMG align=baseline alt="" border=0 src="http://localhost/upimg/0335_p1.jpg"><BR>'
    union all select '<IMG align=baseline alt="" border=0 src="http://localhost/upimg/0335_p1.jpg"><BR>'--定义替换/删除的字符串
    declare @s_str varchar(8000),@d_str varchar(8000)
    select @s_str='中国' --要替换的字符串
    ,@d_str='中华人民共和国' --替换成的字符串--定义游标,循环处理数据
    declare @id int
    declare #tb cursor for select id from hello
    open #tb
    fetch next from #tb into @id
    while @@fetch_status=0
    begin
    --字符串替换处理
    declare @p varbinary(16),@postion int,@rplen int
    select @p=textptr(CONTENT),@rplen=len(@s_str),@postion=charindex(@s_str,CONTENT)-1 from hello where id=@id
    while @postion>0
    begin
    updatetext hello.CONTENT @p @postion @rplen @d_str
    select @postion=charindex(@s_str,CONTENT)-1 from hello where id=@id
    end fetch next from #tb into @id
    end
    close #tb
    deallocate #tb--显示结果
    select * from hello--删除数据测试环境
    drop table hello