begin try
begin transaction
declare
@CurName nvarchar(20),
@CurAge int,
@address nvarchar(20)
declare curデータ cursor local for
select CustomerName,age,address
from customer
open curデータ
fetch next from curデータ
into @CurName,@CurAge,@address
while(@@fetch_status = 0)
BEGIN
-- ここに特定の処理を書く
-- 処理が終わったら変数の入れ替え
fetch next from curデータ
into @CurName,@CurAge,@address
END
close curデータ
deallocate curデータ
commit transaction
end try
begin catch
rollback transaction
end catch
▸ この snippet は実行結果未収録
▸ 実行結果は未収録です
Source収録記事
この snippet は記事の「SQLServerでのカーソルの使い方と書き方 / カーソルの具体的な構文」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。