




已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
sql 中 更新text類型的字段-text字段增加處理-創(chuàng)建測試表create table test(id varchar(3),detail text)insert into testselect 001,A*B-定義添加的的字符串declare s_str varchar(8000),postion intselect s_str=*C -要添加的字符串 ,postion=null -追加的位置,null 加在尾部,0 加在首部,其他值則加在指定位置-字符串添加處理declare p varbinary(16)select p=textptr(detail) from test where id=001updatetext test.detail p postion 0 s_str-顯示處理結(jié)果select * from testgo-刪除測試表drop table test-text字段的替換處理-創(chuàng)建數(shù)據(jù)測試環(huán)境create table test(id varchar(3),txt text)insert into testselect 001,A*Bgo-定義替換的字符串declare s_str varchar(8000),d_str varchar(8000)select s_str=* -要替換的字符串 ,d_str=+ -替換成的字符串-字符串替換處理declare p varbinary(16),postion int,rplen intselect p=textptr(txt) ,rplen=len(s_str) ,postion=charindex(s_str,txt)-1from test where id=001while postion0begin updatetext test.txt p postion rplen d_str select postion=charindex(s_str,txt)-1 from testend-顯示結(jié)果select * from testgo-刪除數(shù)據(jù)測試環(huán)境drop table test-text字段的添加處理存儲過程-全表-創(chuàng)建測試表create table user(uid int,UserLog text)create table order(uid int,state bit)insert into userselect 1,aunion all select 2,bunion all select 3,cinsert into orderselect 1,1union all select 2,0union all select 3,1go-處理的存儲過程CREATE PROCEDURE spUpdateUserLogStrLog text,State intAS-定義游標(biāo),循環(huán)處理數(shù)據(jù)declare uid intdeclare #tb cursor for select a.uid from user a join order b on a.uid=b.uidwhere state=stateopen #tbfetch next from #tb into uidwhile fetch_status=0begin -字符串添加處理 declare p varbinary(16) select p=textptr(UserLog) from user where uid=uid updatetext user.UserLog p null 0 StrLog fetch next from #tb into uidendclose #tbdeallocate #tbgo-調(diào)用示例:exec spUpdateUserLog 123,1-顯示處理結(jié)果select * from usergo-刪除測試環(huán)境drop table user,orderdrop proc spUpdateUserLog/*-測試結(jié)果uid UserLog - -1 a1232 b3 c123(所影響的行數(shù)為 3 行)-*/-text字段的替換處理-全表替換-創(chuàng)建數(shù)據(jù)測試環(huán)境create table test(id varchar(3),txt text)insert into testselect 001,A*Bunion all select 002,A*B-AA*BBgo-定義替換的字符串declare s_str varchar(8000),d_str varchar(8000)select s_str=* -要替換的字符串 ,d_str=+ -替換成的字符串-定義游標(biāo),循環(huán)處理數(shù)據(jù)declare id varchar(3)declare #tb cursor for select id from testopen #tbfetch next from #tb into idwhile fetch_status=0begin -字符串替換處理 declare p varbinary(16),postion int,rplen int select p=textptr(txt) ,rplen=len(s_str) ,postion=charindex(s_str,txt)-1 from test where id=id while postion0 begin updatetext test.txt p postion rplen d_str select postion=charindex(s_str,txt)-1 from test where id=id end fetch next from #tb into idendclose #tbdeallocate #tb-顯示結(jié)果select * from testgo-刪除數(shù)據(jù)測試環(huán)境drop table test*支持text字段處理的僅有:下面的函數(shù)和語句可以與 ntext、text 或 image 數(shù)據(jù)一起使用。函數(shù) 語句DATALENGTH READTEXTPATINDEX SET TEXTSIZESUBSTRING UPDATETEXTTEXTPTR WRITETEXTTEXTVALID1:替換-創(chuàng)建數(shù)據(jù)測試環(huán)境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 intselect p=textptr(aa),rplen=len(s_str),postion=charindex(s_str,aa)-1 from #tbwhile postion0beginupdatetext #tb.aa p postion rplen d_strselect postion=charindex(s_str,aa)-1 from #tbend-顯示結(jié)果select * from #tb-刪除數(shù)據(jù)測試環(huán)境drop table #tb/*全部替換*/DECLARE ptrval binary(16)SELECT ptrval = TEXTPTR(aa)FROM#tbWHERE aa like %數(shù)據(jù)2%if ptrval is not null - 一定要加上此句,否則若找不到數(shù)據(jù)下一句就會(huì)報(bào)錯(cuò)UPDATETEXT #tb.aa ptrval 0 null 數(shù)據(jù)3/*在字段尾添加*/-定義添加的的字符串declare s_str varchar(8000)select s_str=*C -要添加的字符串-字符串添加處理declare p varbinary(16),postion int,rplen intselect p=textptr(deta
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 寵物醫(yī)療市場細(xì)分領(lǐng)域研究報(bào)告-寵物康復(fù)市場規(guī)模分析
- 氣體的化學(xué)性質(zhì)及其應(yīng)用試題及答案
- 曲式理解與音樂創(chuàng)作能力提升的聯(lián)系試題及答案
- 節(jié)目編輯面試題及答案
- 生態(tài)學(xué)復(fù)習(xí)試題及答案
- 家居設(shè)計(jì)中的空間效果與功能結(jié)合研究試題及答案
- 甲方運(yùn)營面試題及答案
- 山東職業(yè)學(xué)院《現(xiàn)代分離工程》2023-2024學(xué)年第二學(xué)期期末試卷
- 情緒邏輯測試題及答案
- 天津農(nóng)學(xué)院《形勢與政策IV》2023-2024學(xué)年第一學(xué)期期末試卷
- 高血壓與青光眼的關(guān)系
- 專題03 根據(jù)音標(biāo)寫單詞??家族e(cuò)100題-譯林版七年級上學(xué)期英語期末考點(diǎn)復(fù)習(xí)專項(xiàng)訓(xùn)練
- 數(shù)字經(jīng)濟(jì)對廣東省經(jīng)濟(jì)影響研究
- 編制氣候可行性論證報(bào)告
- 2024年上海銀聯(lián)數(shù)據(jù)服務(wù)有限公司招聘筆試參考題庫含答案解析
- 工業(yè)園區(qū)規(guī)劃環(huán)評報(bào)告書
- 養(yǎng)老院項(xiàng)目組織結(jié)構(gòu)方案
- 士兵軍考模擬卷(化學(xué))
- 2023-2024年版中國運(yùn)動(dòng)康復(fù)產(chǎn)業(yè)白皮書-運(yùn)動(dòng)康復(fù)產(chǎn)業(yè)聯(lián)盟-202310
- 小升初成語運(yùn)用題有答案
- 無倉儲經(jīng)營企業(yè)管理制度、責(zé)任制、操作規(guī)程匯編
評論
0/150
提交評論