gpt4 book ai didi

sql-server - 是否必须关闭 T-SQL 存储过程中的游标?

转载 作者:行者123 更新时间:2023-12-02 20:53:54 26 4
gpt4 key购买 nike

我们在 PayPal 订单方面遇到了间歇性问题,我一直在深入研究我们的代码。我们在特定存储过程中收到一个异常,显示“等待操作超时”。在存储过程中,我可以看到一个名为 item_cursor 的游标被声明并随后打开,但它从未关闭。存储过程直接结束,无需调用 close item_cursor(或 DEALLOCATE item_cursor)。

我是前端开发人员而不是后端开发人员,所以我有点超出了我的深度,但这可能是导致问题的原因吗?

最佳答案

这取决于cursor is declared如何:

LOCAL

Specifies that the scope of the cursor is local to the batch, stored procedure, or trigger in which the cursor was created. The cursor name is only valid within this scope. ... The cursor is implicitly deallocated when the batch, stored procedure, or trigger terminates, unless the cursor was passed back in an OUTPUT parameter. If it is passed back in an OUTPUT parameter, the cursor is deallocated when the last variable referencing it is deallocated or goes out of scope.

GLOBAL

Specifies that the scope of the cursor is global to the connection. The cursor name can be referenced in any stored procedure or batch executed by the connection. The cursor is only implicitly deallocated at disconnect.

(我的强调)

然后,它继续解释如果两者都没有指定,它如何选择默认值,但如果您没有更改系统上的任何其他内容,则默认情况下它将是GLOBAL,在本例中这意味着,是的,它将“泄漏”。如果光标持有任何锁,它将继续持有这些锁,直到您的连接断开。

关于sql-server - 是否必须关闭 T-SQL 存储过程中的游标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118993/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com