USE pubs
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_lname FROM authors
WHERE au_lname LIKE 'B%'
ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch.
FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor
GO
GO
DECLARE authors_cursor CURSOR FOR
SELECT au_lname FROM authors
WHERE au_lname LIKE 'B%'
ORDER BY au_lnameOPEN authors_cursor-- Perform the first fetch.
FETCH NEXT FROM authors_cursor-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM authors_cursor
ENDCLOSE authors_cursor
DEALLOCATE authors_cursor
GO
open my_cursor
FETCH NEXT FROM my_cursor
WHILE @@FETCH_STATUS = 0
BEGIN
select * from tt1
FETCH NEXT FROM my_cursor
end結果:(影響 1 個資料列)
(影響 3 個資料列)
(影響 1 個資料列)
(影響 3 個資料列)
(影響 1 個資料列)
(影響 3 個資料列)
(影響 1 個資料列)
(影響 3 個資料列)
(影響 1 個資料列)
(影響 3 個資料列)
(影響 0 個資料列)
如果写成存储过程
exec pro_name
就显示一次