小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

text字段

 qzg589 2005-09-09

text字段

[日期:2005-07-08] 來源:CSDN  作者: [字體: ]

支持text字段處理的僅有:
下面的函數(shù)和語句可以與 ntext、text 或 image 數(shù)據(jù)一起使用。
函數(shù)          語句
DATALENGTH    READTEXT
PATINDEX      SET TEXTSIZE
SUBSTRING     UPDATETEXT
TEXTPTR       WRITETEXT
TEXTVALID


1:替換

--創(chuàng)建數(shù)據(jù)測(cè)試環(huán)境
create table #tb(aa text)
insert into #tb select ‘a(chǎn)bc123abc123,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

--顯示結(jié)果
select * from #tb

--刪除數(shù)據(jù)測(cè)試環(huán)境
drop table #tb

/****************全部替換************************/
DECLARE @ptrval binary(16)
SELECT @ptrval = TEXTPTR(aa)  FROM  #tb  WHERE aa like ‘%數(shù)據(jù)2%‘
if @ptrval is not null        -- 一定要加上此句,否則若找不到數(shù)據(jù)下一句就會(huì)報(bào)錯(cuò)
 UPDATETEXT #tb.aa @ptrval 0 null ‘?dāng)?shù)據(jù)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


總結(jié):
1:Text字段類型不能直接用replace函數(shù)來替換,必須用updatetext
 2:字段比較不能用 where 字段 = ‘某數(shù)據(jù)’,可以用like來代替
 3:updatetext時(shí),若@ptrval值為空會(huì)出錯(cuò),需注意。

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多