sql 游標 初次使用

2021-05-23 15:15:56 字數 536 閱讀 9362

use brow

go declare browser_cursor  cursor  for  select browsertype  from  tbbrowser --定義游標

open  browser_cursor--開啟游標

declare @browsertype nvarchar(10)--儲存迴圈出來的值

fetch  next  from  browser_cursor into @browsertype --提取游標

while @@fetch_status = 0 --條件開始迴圈

begin

print   @browsertype --列印操作 在這裡你可以對迴圈得到的資料進行你想要的操作。

fetch  next  from  browser_cursor  into @browsertype --繼續提取游標

end

close  browser_cursor --關閉游標

deallocate  browser_cursor --釋放游標

SQL游標使用

使用迴圈控制 declare a int set a 0 while a 10 begin print a set a a 1 end 獲取系統時間 select getdate exec sp addlinkedserver mailoudb exec sp addlinkedserver dbl...

sql 游標使用簡記

if exists select from sys.objects where object id object id n dbo payee del and type in n p n pc begin drop procedure payee del endgo create proc dbo ...

SQL 游標的使用

我們都知道在關聯式資料庫中,都是面向集合進行查詢的,而游標卻是化整為零,是按行查詢的,舉個例子比如說之前那個壕買了99臺蘋果6,他可以一次性就買了99臺,這正是我們平常使用sql的方式,他也可以分成若干次買,這就是游標的方式,一次只查詢一行。游標分為游標型別和游標變數,對於游標變數來說,游標變數支援...