動くコード図鑑技術記事現場の渡り方キャリア論すべての記事About
SQL

カーソルの具体的な構文

出典: SQLServerでのカーソルの使い方と書き方!SQLServerでのカーソルの使い方と書き方 / カーソルの具体的な構文

カーソルの具体的な構文 (sql)#7a18a9b55c22
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 は実行結果未収録
▸ 実行結果は未収録です
  • id: #7a18a9b55c22
  • lines: 39
  • extracted: 2026-06-10

Source収録記事

この snippet は記事の「SQLServerでのカーソルの使い方と書き方 / カーソルの具体的な構文」セクションに登場する。コードの前後の文脈・ハマりどころの解説は記事本文で。

同じ記事から

2
図鑑トップ