有两个方法可以查看Cursor是否Open:
1.查询syscursors系统表:
Select*fromMASTER.dbo.syscursors
2. 使用CURSOR_STATUS函数:
比如:
CREATETABLE#TMP
(
iiint
)
GO
INSERTINTO#TMP(ii)VALUES(1)
INSERTINTO#TMP(ii)VALUES(2)
INSERTINTO#TMP(ii)VALUES(3)
GO
--Create a cursor.
DECLAREcurCURSOR
FORSELECT*FROM#TMP
--Display the status of the cursor before and after opening
--closing the cursor.
SELECTCURSOR_STATUS('global','cur')AS'After declare'
OPENcur
SELECTCURSOR_STATUS('global','cur')AS'After Open'
CLOSEcur
SELECTCURSOR_STATUS('global','cur')AS'After Close'
--Remove the cursor.
DEALLOCATEcur
--Drop the table.
DROPTABLE#TMP
本文转自 lzf328 51CTO博客,原文链接:http://blog.51cto.com/lzf328/1224149