這篇文章主要講解了“SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)的使用方法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)的使用方法”吧!
1、建立基表
createtableplanwork(planidint,empidint)insertintoplanworkvalues(1,100)insertintoplanworkvalues(2,200)insertintoplanworkvalues(3,300)insertintoplanworkvalues(4,400)insertintoplanworkvalues(5,500)insertintoplanworkvalues(6,600)insertintoplanworkvalues(7,700)insertintoplanworkvalues(8,800)select*fomplanwork
2、建立函數(shù)
dropfunctionfindworkplancreatefunctionfindworkplan(@numint)returnsintasbegindeclare@eidintset@eid=(selectempidfromplanworkwhereplanid=@num)return@eid;end;
3、測試函數(shù)
selectdbo.findworkplan(3)
SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)怎么使用
4、利用游標(biāo)調(diào)用函數(shù)
4.1、創(chuàng)建一個(gè)表,利用這個(gè)表里面的數(shù)值得到workplan表里面對應(yīng)的empno
createtablexb_test1(xidint)insertintoxb_test1values(1)insertintoxb_test1values(2)insertintoxb_test1values(3)insertintoxb_test1values(4)insertintoxb_test1values(5)insertintoxb_test1values(6)insertintoxb_test1values(7)insertintoxb_test1values(8)select*fromxb_test1
4.2、只能用循環(huán)遍歷xb_test1表分別找出對應(yīng)表workplan的empno,考慮到需遍歷整個(gè)xb_test1表,所以決定用游標(biāo),不知道用oracle的with函數(shù)怎么樣?該WHILE結(jié)構(gòu)測試用于游標(biāo)的函數(shù)@@FETCH_STATUS的返回值。因?yàn)锧@FETCH_STATUS可能返回–2、-1或0,所以,所有的情況都應(yīng)進(jìn)行測試。假如某一行在開始執(zhí)行此存儲過程以后從游標(biāo)結(jié)果中刪除,將跳過該行。成功提取(0)后將執(zhí)行BEGIN...END循環(huán)內(nèi)部的SELECT語句。
declareempno_cursorcursorforselectxidfromxb_test1openempno_cursordeclare@aint,@resultintfetchnextfromempno_cursorinto@awhile(@@fetch_status<>-1)beginif(@@fetch_status<>-2)begin--print@aset@result=(selectdbo.findworkplan(@a))print@resultendfetchnextfromempno_cursorinto@aendcloseempno_cursordeallocateempno_cursor。
感謝各位的閱讀,以上就是“SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)的使用方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)的使用方法這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
本文名稱:SQLServer2005數(shù)據(jù)庫游標(biāo)調(diào)用函數(shù)的使用方法-創(chuàng)新互聯(lián)
文章位置:http://aaarwkj.com/article46/idpeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、網(wǎng)站建設(shè)、ChatGPT、動態(tài)網(wǎng)站、域名注冊、標(biāo)簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容