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