• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

text字段

发布: 2007-7-02 11:08 | 作者: admin | 来源: | 查看: 16次 | 进入软件测试论坛讨论

领测软件测试网
支持text字段处理的仅有:
下面的函数和语句可以与 ntext、text 或 image 数据一起使用。
函数          语句
DATALENGTH    READTEXT
PATINDEX      SET TEXTSIZE
SUBSTRING     UPDATETEXT
TEXTPTR       WRITETEXT
TEXTVALID


1:替换

--创建数据测试环境
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

/****************全部替换************************/
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(aa)  FROM  #tb  WHERE aa like @#%数据2%@#
if @ptrval is not null        -- 一定要加上此句,否则若找不到数据下一句就会报错
 UPDATETEXT #tb.aa @ptrval 0 null @#数据3@#


/****************在字段尾添加**********************************/
--定义添加的的字符串
declare @s_str varchar(8000)
select @s_str=@#*C@#   --要添加的字符串
--字符串添加处理
declare @p varbinary(16),@postion int,@rplen int
select @p=textptr(detail) from test where id=@#001@#
updatetext test.detail @p null null @s_str


总结:
1:Text字段类型不能直接用replace函数来替换,必须用updatetext
 2:字段比较不能用 where 字段 = ‘某数据’,可以用like来代替
 3:updatetext时,若@ptrval值为空会出错,需注意。

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网