![sql中利用 text更新,插入text類型的字段的方法帶完整實(shí)例.doc_第1頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/13/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e53/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e531.gif)
![sql中利用 text更新,插入text類型的字段的方法帶完整實(shí)例.doc_第2頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/13/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e53/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e532.gif)
![sql中利用 text更新,插入text類型的字段的方法帶完整實(shí)例.doc_第3頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/13/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e53/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e533.gif)
![sql中利用 text更新,插入text類型的字段的方法帶完整實(shí)例.doc_第4頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/13/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e53/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e534.gif)
![sql中利用 text更新,插入text類型的字段的方法帶完整實(shí)例.doc_第5頁(yè)](http://file.renrendoc.com/FileRoot1/2020-1/13/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e53/cb4c5dcf-e4c5-4092-80d6-632b4b9a7e535.gif)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
sql 中 更新text類型的字段-text字段增加處理-創(chuàng)建測(cè)試表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-刪除測(cè)試表drop table test-text字段的替換處理-創(chuàng)建數(shù)據(jù)測(cè)試環(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ù)測(cè)試環(huán)境drop table test-text字段的添加處理存儲(chǔ)過程-全表-創(chuàng)建測(cè)試表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-處理的存儲(chǔ)過程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-刪除測(cè)試環(huán)境drop table user,orderdrop proc spUpdateUserLog/*-測(cè)試結(jié)果uid UserLog - -1 a1232 b3 c123(所影響的行數(shù)為 3 行)-*/-text字段的替換處理-全表替換-創(chuàng)建數(shù)據(jù)測(cè)試環(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ù)測(cè)試環(huán)境drop table test*支持text字段處理的僅有:下面的函數(shù)和語句可以與 ntext、text 或 image 數(shù)據(jù)一起使用。函數(shù) 語句DATALENGTH READTEXTPATINDEX SET TEXTSIZESUBSTRING UPDATETEXTTEXTPTR WRITETEXTTEXTVALID1:替換-創(chuàng)建數(shù)據(jù)測(cè)試環(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ù)測(cè)試環(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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年滌綸披巾項(xiàng)目可行性研究報(bào)告
- 2025年反絨革項(xiàng)目可行性研究報(bào)告
- 2025年度綠色建筑節(jié)能改造施工合同答辯狀
- 2025年度建筑節(jié)能工程施工合同規(guī)范范本
- 2025年素牛排項(xiàng)目投資可行性研究分析報(bào)告
- 2025年度大數(shù)據(jù)股份分配與智慧城市建設(shè)協(xié)議
- 2024-2030年中國(guó)舞臺(tái)煙霧機(jī)行業(yè)發(fā)展前景預(yù)測(cè)及投資策略研究報(bào)告
- 2024年車身廣告行業(yè)市場(chǎng)深度分析及發(fā)展前景預(yù)測(cè)報(bào)告
- 2025年不飽和樹脂設(shè)備行業(yè)深度研究分析報(bào)告
- 2025年度全球貿(mào)易代理銷售合作協(xié)議
- 《工程電磁場(chǎng)》配套教學(xué)課件
- 遼寧省錦州市各縣區(qū)鄉(xiāng)鎮(zhèn)行政村村莊村名居民村民委員會(huì)明細(xì)及行政區(qū)劃代碼
- 改革開放的歷程(終稿)課件
- 職位管理手冊(cè)
- IPQC首檢巡檢操作培訓(xùn)
- 餐飲空間設(shè)計(jì)課件ppt
- 肉制品加工技術(shù)完整版ppt課件全套教程(最新)
- (中職)Dreamweaver-CC網(wǎng)頁(yè)設(shè)計(jì)與制作(3版)電子課件(完整版)
- 行政人事助理崗位月度KPI績(jī)效考核表
- 紀(jì)檢監(jiān)察機(jī)關(guān)派駐機(jī)構(gòu)工作規(guī)則全文詳解PPT
- BP-2C 微機(jī)母線保護(hù)裝置技術(shù)說明書 (3)
評(píng)論
0/150
提交評(píng)論