当我在我的SQL客户端中打开SHOWPLAN功能时,我试图弄清楚为什么我得到了一个“无效的游标状态”错误。
我运行的代码如下:
SET SHOWPLAN_XML ON;
Select *
From Sys.Objects
SET SHOWPLAN_XML OFF;This is the error I get when I run this
任何帮助都将不胜感激
发布于 2016-07-12 23:36:00
这应该可以修复您的错误。
SET SHOWPLAN_XML ON;
GO
Select * From Sys.Objects
GO
SET SHOWPLAN_XML OFF;
GO发布于 2016-07-13 01:25:41
似乎您有一个光标处于打开状态。你需要记住DEALLOCATE光标(它的代码不是你问题的一部分)
全局删除{{
cursor_name }| @cursor_variable_name }
因为没有提供开放游标代码,所以我不能告诉您要使用的参数。
我相信这会对close all cursors有帮助
-- Declare a cursor variable to hold the cursor output variable
-- from sp_cursor_list.
DECLARE @Report CURSOR;
-- Execute sp_cursor_list into the cursor variable.
EXEC master.dbo.sp_cursor_list @cursor_return = @Report OUTPUT,
@cursor_scope = 2;
-- Fetch all the rows from the sp_cursor_list output cursor.
FETCH NEXT from @Report;
WHILE (@@FETCH_STATUS <> -1)
BEGIN
FETCH NEXT from @Report;
END
-- Close and deallocate the cursor from sp_cursor_list.
CLOSE @Report;
DEALLOCATE @Report;
GO 最重要的是,你还有一个错误。
消息1067,级别15,状态1,第0行SET SHOWPLAN语句必须是批处理中的唯一语句。
如错误所示,您需要将其分解为不同的批处理。SET SHOWPLAN必须在批处理中单独存在。有几个命令需要它们自己的批处理
试试这个:
SET SHOWPLAN_XML ON;
GO
SELECT * FROM Sys.Objects;
GO
SET SHOWPLAN_XML OFF;
GOhttps://stackoverflow.com/questions/38333146
复制相似问题