sql server 游标的使用方法
數(shù)據(jù)庫(kù)游標(biāo):是面向行來(lái)取數(shù)據(jù)集合的標(biāo)識(shí),可以很好的彌補(bǔ)面向表或數(shù)據(jù)集合閱讀數(shù)據(jù)的不便之處;游標(biāo)的內(nèi)存消耗也很大,所以使用有標(biāo)簽還要衡量是否值得使用游標(biāo)標(biāo)識(shí)。
游標(biāo)舉例:
declare test_cursor cursor? --定義游標(biāo)并初始化
for
select testName from Username
open test_cursor??????????? -- 打開(kāi)游標(biāo)
declare @temName Varchar(10)
fetch next from test_cursor into @temName? -- 取一條數(shù)據(jù)賦值給臨時(shí)變量
while @@fetch_status = 0?? --獲取下一條數(shù)據(jù)是否成功的標(biāo)識(shí) 0:成功; -1:獲取數(shù)據(jù)失敗或者此行不在結(jié)果集中; -2:獲取的行不存在。
begin
/******
在此可以進(jìn)行數(shù)據(jù)增刪改等操作
******/
print @temName?
fetch next from test_cursor into @temName?-- 取一條數(shù)據(jù)賦值給臨時(shí)變量
end
colse test_cursor? --關(guān)閉游標(biāo)
deallocate test_cursor? --銷毀游標(biāo)
游標(biāo)的格式就是這個(gè)樣子的,主要是根據(jù)實(shí)際數(shù)據(jù)情況進(jìn)行使用。
轉(zhuǎn)載于:https://www.cnblogs.com/Janzen/p/5667458.html
總結(jié)
以上是生活随笔為你收集整理的sql server 游标的使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: scala shuffle
- 下一篇: 在MyEclipse中更换或修改svn的