sql 游標的關閉和釋放


如果不關閉游標,就會

消息 16915,級別 16,狀態 1,過程  (過程名),第 xx 行
名為 'c1' 的游標已存在。
消息 16905,級別 16,狀態 1,過程  (過程名),第 xx 行
游標已打開。

 

如何關閉游標,其實和定義游標和打開游標是對應的,sql如下:

declare c1 cursor for -- 定義游標
select record_id from cis_cp_occ_main where enc_id=@enc_id
open c1  -- 打開游標
fetch next from c1 into @ids
while @@FETCH_STATUS=0
begin
    update table set table.a='1' where ......
    fetch next from c1 into @ids
end
close c1 --關閉游標
deallocate c1 -- 釋放游標

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM