且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何判断游标是否存在?

更新时间:2022-09-27 21:55:54

有两个方法可以查看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