日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

替換text字段的儲(chǔ)存過(guò)程

系統(tǒng) 1778 0

ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead
  從上文可以看到text,ntext等類(lèi)型將會(huì)被ms sqlserver拋棄,取而代之的是varchar(max)等.
  預(yù)計(jì)也將會(huì)取消專(zhuān)門(mén)針對(duì)text等類(lèi)型的操作函數(shù),例如textptr,updatetext等。
  但是目前有許多現(xiàn)存系統(tǒng)仍然存在text類(lèi)型的字段,因?yàn)榉N種原因已經(jīng)不能修改數(shù)據(jù)庫(kù)結(jié)構(gòu)。
  但是我們可以在新寫(xiě)的sql語(yǔ)句及存儲(chǔ)過(guò)程中采用新的方法,以備將來(lái)mssql server拋棄專(zhuān)門(mén)針對(duì)text等類(lèi)型的操作函數(shù)后修改程序的麻煩。
  下面是一個(gè)簡(jiǎn)單的替換例子,
  針對(duì)text類(lèi)型的字符串替換:
  設(shè)有表 T(id int not null,info text)
  要求替換info中的'abc'為'123'
  一般的存儲(chǔ)過(guò)程會(huì)寫(xiě)成:
  drop procedure dbo.procedure_1
  go
  set ANSI_NULLS ON
  set QUOTED_IDENTIFIER ON
  go
  create procedure dbo.procedure_1
  as
  declare @ptr varbinary(16)
  declare @ID int
  declare @Position int,@len int
  declare @strsrc char(3)
  declare @strdsc char(3)
  set @strtmp='abc'
  set @strdsc='123'
  set @len=3
  declare replace_Cursor scroll Cursor
  for
  select textptr([info]),id from T
  for read only
  open replace_Cursor
  fetch next from replace_Cursor into @ptr,@ID
  while @@fetch_status=0
  begin
   select @Position=patindex(
'%'+@strsrc+'%',
   while @Position>0
   begin
   set @Position=@Position-1
   updatetext T.[info] @ptr @Position @len @strdsc
   select @Position=patindex(
'%'+@strsrc+'%',
   end
   fetch next from replace_Cursor into @ptr,@ID
  end
  close replace_Cursor
  deallocate replace_Cursor
  go
  其中用到了text專(zhuān)用的函數(shù) updatetext
  現(xiàn)在我們改寫(xiě)成
  drop procedure dbo.procedure_1
  go
  set ANSI_NULLS ON
  set QUOTED_IDENTIFIER ON
  go
  create procedure dbo.procedure_1
  as
  declare @ID int
  declare @strtmp varchar(max)
  declare @strsrc char(3),@strdsc char(3)
  set @strsrc = 'abc'
  set @strdsc = '123'
  declare replace_Cursor scroll Cursor
  for
  select id from testtable
  --for read only
  open replace_Cursor
  fetch next from replace_Cursor into @ID
  while @@fetch_status=0
  begin
   select @strtmp = [info] from testtable where
id=@ID
   select @strtmp = Replace(@strtmp,@strsrc,@strdsc)
   update T set [info] = @strtmp where
id=@ID
   fetch next from replace_Cursor into @ID
  end
  close replace_Cursor
  deallocate replace_Cursor
  go
  這樣,無(wú)論info字段改成char,nchar,text都好,一樣均可通用

替換text字段的儲(chǔ)存過(guò)程


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 汉阴县| 吉水县| 盐池县| 龙陵县| 奉节县| 南澳县| 大丰市| 峨眉山市| 丰顺县| 遂平县| 武夷山市| 舞钢市| 六盘水市| 商丘市| 珲春市| 石楼县| 宣汉县| 松阳县| 台北县| 临泉县| 连平县| 阿瓦提县| 隆回县| 高碑店市| 岳池县| 安岳县| 杭锦旗| 周至县| 秦皇岛市| 阿勒泰市| 宝应县| 临西县| 科技| 奈曼旗| 出国| 叙永县| 桃江县| 鹿泉市| 吴忠市| 仙游县| 宣汉县|