首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何找出错误发生在存储过程的哪一行?

如何找出错误发生在存储过程的哪一行?
EN

Stack Overflow用户
提问于 2008-10-29 20:47:12
回答 1查看 3.1K关注 0票数 6

当我尝试在MS SQL 2005数据库上运行特定的存储过程时,我得到如下错误:

代码语言:javascript
复制
Subquery returned more than 1 value. This is not permitted when
the subquery follows =, !=, <, <= , >, >= or when the subquery
is used as an expression

查询中的SP很长,并调用其他SP。这个错误显然是由SQL本身产生的,并在调用堆栈中一直向上返回,但没有提到是哪个SP或行号导致了这个问题。如何才能找出抛出错误的位置,以便更轻松地进行调试?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2008-10-29 20:49:52

使用Try/Catch block应该会给你想要的东西。

在CATCH块的作用域中,可以使用以下系统函数来获取有关导致CATCH块执行的错误的信息:

代码语言:javascript
复制
* ERROR_NUMBER() returns the number of the error.
* ERROR_SEVERITY() returns the severity.
* ERROR_STATE() returns the error state number.
* ERROR_PROCEDURE() returns the name of the stored procedure or trigger where the error occurred.
* ERROR_LINE() returns the line number inside the routine that caused the error.
* ERROR_MESSAGE() returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times.

因此,在您的示例中,ERROR_LINE()和ERROR_PROCEDURE()应该是您想要的……

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/248354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档