如题所述
--æµè¯
DECLARE @SNAME VARCHAR(20)
DECLARE DD CURSOR FOR SELECT SNAME FROM S
OPEN DD
--楼ä¸è¯´ç对.ä½ è¦çæ¯å¤æ游æ æ¯å¦åå¨
select * from MASTER.dbo.syscursors where cursor_name='DD'
--以ä¸æä½ä¸ºå¤æ游æ æ¯å¦åå¨çåæ¶æ£æµæ¸¸æ ç¶æã
SELECT (CASE WHEN CURSOR_STATUS('global','DD')=1 THEN '游æ çç»æéè³å°æä¸è¡'
WHEN CURSOR_STATUS('global','DD')=0 THEN '游æ çç»æé为空'
WHEN CURSOR_STATUS('global','DD')=-1 THEN '游æ è¢«å ³é'
WHEN CURSOR_STATUS('global','DD')=-2 THEN '游æ ä¸éç¨'
WHEN CURSOR_STATUS('global','DD')=-3 THEN '游æ ä¸åå¨' END) AS RESULT
/*è¿åç»æï¼
1
游æ çç»æéè³å°æä¸è¡ã
对äºä¸åºåç游æ åé®é游æ ï¼ç»æéè³å°æä¸è¡ã
对äºå¨æ游æ ï¼ç»æéå¯ä»¥æé¶è¡ãä¸è¡æå¤è¡ã
åé ç»è¯¥åéç游æ å·²æå¼ã
对äºä¸åºåç游æ åé®é游æ ï¼ç»æéè³å°æä¸è¡ã
对äºå¨æ游æ ï¼ç»æéå¯ä»¥æé¶è¡ãä¸è¡æå¤è¡ã
0
游æ çç»æé为空ã*
åé ç»è¯¥åéç游æ å·²ç»æå¼ï¼ç¶èç»æéè¯å®ä¸ºç©ºã*
-1
游æ è¢«å ³éã
åé ç»è¯¥åéç游æ è¢«å ³éã
-2
ä¸éç¨ã
å¯ä»¥æ¯ï¼
å åè°ç¨çè¿ç¨å¹¶æ²¡æå°æ¸¸æ åé ç» OUTPUT åéã
å åè°ç¨çè¿ç¨ä¸º OUTPUT åéåé äºæ¸¸æ ï¼ç¶èå¨è¿ç¨ç»ææ¶ï¼æ¸¸æ å¤äºå ³éç¶æãå æ¤ï¼æ¸¸æ 被éæ¾ï¼å¹¶ä¸æ²¡æè¿åè°ç¨è¿ç¨ã
没æå°æ¸¸æ åé ç»å·²å£°æç游æ åéã
-3
å ·ææå®å称ç游æ ä¸åå¨ã
å ·ææå®å称ç游æ åé并ä¸åå¨ï¼æè å³ä½¿åå¨è¿æ ·ä¸ä¸ªæ¸¸æ åéï¼ä½å¹¶æ²¡æç»å®åé 游æ ã
DECLARE @SNAME VARCHAR(20)
DECLARE DD CURSOR FOR SELECT SNAME FROM S
OPEN DD
--楼ä¸è¯´ç对.ä½ è¦çæ¯å¤æ游æ æ¯å¦åå¨
select * from MASTER.dbo.syscursors where cursor_name='DD'
--以ä¸æä½ä¸ºå¤æ游æ æ¯å¦åå¨çåæ¶æ£æµæ¸¸æ ç¶æã
SELECT (CASE WHEN CURSOR_STATUS('global','DD')=1 THEN '游æ çç»æéè³å°æä¸è¡'
WHEN CURSOR_STATUS('global','DD')=0 THEN '游æ çç»æé为空'
WHEN CURSOR_STATUS('global','DD')=-1 THEN '游æ è¢«å ³é'
WHEN CURSOR_STATUS('global','DD')=-2 THEN '游æ ä¸éç¨'
WHEN CURSOR_STATUS('global','DD')=-3 THEN '游æ ä¸åå¨' END) AS RESULT
/*è¿åç»æï¼
1
游æ çç»æéè³å°æä¸è¡ã
对äºä¸åºåç游æ åé®é游æ ï¼ç»æéè³å°æä¸è¡ã
对äºå¨æ游æ ï¼ç»æéå¯ä»¥æé¶è¡ãä¸è¡æå¤è¡ã
åé ç»è¯¥åéç游æ å·²æå¼ã
对äºä¸åºåç游æ åé®é游æ ï¼ç»æéè³å°æä¸è¡ã
对äºå¨æ游æ ï¼ç»æéå¯ä»¥æé¶è¡ãä¸è¡æå¤è¡ã
0
游æ çç»æé为空ã*
åé ç»è¯¥åéç游æ å·²ç»æå¼ï¼ç¶èç»æéè¯å®ä¸ºç©ºã*
-1
游æ è¢«å ³éã
åé ç»è¯¥åéç游æ è¢«å ³éã
-2
ä¸éç¨ã
å¯ä»¥æ¯ï¼
å åè°ç¨çè¿ç¨å¹¶æ²¡æå°æ¸¸æ åé ç» OUTPUT åéã
å åè°ç¨çè¿ç¨ä¸º OUTPUT åéåé äºæ¸¸æ ï¼ç¶èå¨è¿ç¨ç»ææ¶ï¼æ¸¸æ å¤äºå ³éç¶æãå æ¤ï¼æ¸¸æ 被éæ¾ï¼å¹¶ä¸æ²¡æè¿åè°ç¨è¿ç¨ã
没æå°æ¸¸æ åé ç»å·²å£°æç游æ åéã
-3
å ·ææå®å称ç游æ ä¸åå¨ã
å ·ææå®å称ç游æ åé并ä¸åå¨ï¼æè å³ä½¿åå¨è¿æ ·ä¸ä¸ªæ¸¸æ åéï¼ä½å¹¶æ²¡æç»å®åé 游æ ã
温馨提示:答案为网友推荐,仅供参考