sql server中带游标的存储过程第一次执行可以显示结果集,但第二次后就不可以了,why?
CREATEPROCEDUREstu_cursor@stu_cursorCURSORVARYINGOUTPUTASSET@stu_cursor=CURSORFORWARD...
CREATE PROCEDURE stu_cursor
@stu_cursor CURSOR VARYING OUTPUT
AS
SET @stu_cursor=CURSOR FORWARD_ONLY STATIC FOR
SELECT *
FROM xs
OPEN @stu_cursor
go
DECLARE @MyCursor CURSOR
EXECUTE stu_cursor @stu_cursor=@MyCursor OUTPUT
WHILE(@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM @MyCursor
END
CLOSE @MyCursor
DEALLOCATE @MyCursor
GO 展开
@stu_cursor CURSOR VARYING OUTPUT
AS
SET @stu_cursor=CURSOR FORWARD_ONLY STATIC FOR
SELECT *
FROM xs
OPEN @stu_cursor
go
DECLARE @MyCursor CURSOR
EXECUTE stu_cursor @stu_cursor=@MyCursor OUTPUT
WHILE(@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM @MyCursor
END
CLOSE @MyCursor
DEALLOCATE @MyCursor
GO 展开
2个回答
展开全部
CREATE PROCEDURE stu_cursor
@stu_cursor CURSOR VARYING OUTPUT
AS
SET @stu_cursor=CURSOR FORWARD_ONLY STATIC FOR
SELECT *
FROM xs
OPEN @stu_cursor
-- 这里的go去掉-------------
DECLARE @MyCursor CURSOR
EXECUTE stu_cursor @stu_cursor=@MyCursor OUTPUT
WHILE(@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM @MyCursor
END
CLOSE @MyCursor
DEALLOCATE @MyCursor
GO
@stu_cursor CURSOR VARYING OUTPUT
AS
SET @stu_cursor=CURSOR FORWARD_ONLY STATIC FOR
SELECT *
FROM xs
OPEN @stu_cursor
-- 这里的go去掉-------------
DECLARE @MyCursor CURSOR
EXECUTE stu_cursor @stu_cursor=@MyCursor OUTPUT
WHILE(@@FETCH_STATUS=0)
BEGIN
FETCH NEXT FROM @MyCursor
END
CLOSE @MyCursor
DEALLOCATE @MyCursor
GO
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询