获取当前执行的SQL游标语句

发布于 2024-11-28 07:10:28 字数 359 浏览 3 评论 0原文

http://msdn.microsoft.com/en-us/library/ms190346.aspx

它在语句开始/结束偏移下的部分中表示您可以将其与 dm_exec_sql_text 结合使用来获取当前正在执行的游标语句。这样做的命令是什么?

我有一个相当大的 SP,当它到达游标逻辑循环 'while (@@fetch_status =0) 时冻结,我想看看它是否是我认为的确切执行语句,我也想查看此语句的参数,以便我可以准确地了解为什么游标从未退出,或者只是为什么循环内的语句无法完成。谢谢!

http://msdn.microsoft.com/en-us/library/ms190346.aspx

It says here in the section under the statement start/end offset that you can use that in conjunction with dm_exec_sql_text to get the currently executing cursor statement. What would be the command for that?

I have a fairly large SP that froze when it reached a cursor logic loop 'while (@@fetch_status =0) and I'd like to see if it is the exact executing statement I think it is, and I'd also like to see the parameters for this statement so I can see exactly why the cursor either never exited, or just why the statement inside the loop won't complete. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

£噩梦荏苒 2024-12-05 07:10:28

从这个开始

SELECT * FROM(SELECT session_id,
     COALESCE(OBJECT_NAME(s2.objectid),'Ad-Hoc') AS ProcName,
    (SELECT TOP 1 SUBSTRING(s2.TEXT,statement_start_offset / 2+1 ,
      ( (CASE WHEN statement_end_offset = -1
         THEN (LEN(CONVERT(NVARCHAR(MAX),s2.TEXT)) * 2)
         ELSE statement_end_offset END)  - statement_start_offset) / 2+1))  
       AS sql_statement
FROM sys.dm_exec_requests AS s1
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS s2 ) x
WHERE  sql_statement 
NOT like 'SELECT * FROM(SELECT session_id,COALESCE(%'

start with this

SELECT * FROM(SELECT session_id,
     COALESCE(OBJECT_NAME(s2.objectid),'Ad-Hoc') AS ProcName,
    (SELECT TOP 1 SUBSTRING(s2.TEXT,statement_start_offset / 2+1 ,
      ( (CASE WHEN statement_end_offset = -1
         THEN (LEN(CONVERT(NVARCHAR(MAX),s2.TEXT)) * 2)
         ELSE statement_end_offset END)  - statement_start_offset) / 2+1))  
       AS sql_statement
FROM sys.dm_exec_requests AS s1
CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS s2 ) x
WHERE  sql_statement 
NOT like 'SELECT * FROM(SELECT session_id,COALESCE(%'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文