Skip to content

Instantly share code, notes, and snippets.

@ichiroku11
Created June 8, 2012 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ichiroku11/2892705 to your computer and use it in GitHub Desktop.
Save ichiroku11/2892705 to your computer and use it in GitHub Desktop.
カーソルの使い方
-- cursorを宣言
declare cur cursor
for
select ...
-- cursorを開く
open cur;
-- 1行ごとにデータを取り出す
fetch next from cur into @v1, @v2, ...;
-- ループ
while @@fetch_status = 0 -- fetchは正常に実行された
begin
-- 1行ごとにデータを取り出す
fetch next from cur into @v1, @v2, ...;
end
-- カーソルを閉じる
close cur;
-- カーソルに割り当てられたリソースを解放
deallocate cur;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment