MSDN关于存储过程默认返回值
谁能准确指出 MSDN 所说的如果没有错误发生,每个用户存储过程默认返回 0 的地方吗?换句话说,
IF someStatement
BEGIN
RETURN 1
END
如果 someStatement 为 false 并且没有发生错误,我能否确定下面给出的示例代码在作为存储过程时应该始终返回零?
我知道它实际上是这样工作的,但我没有找到微软对此的任何明确声明。
Could anyone point exactly where MSDN says thet every user stored procedure returns 0 by default if no error happens? In other words, could I be sure that example code given below when being a stored procedure
IF someStatement
BEGIN
RETURN 1
END
should always return zero if someStatement is false and no error occurs?
I know that it actually works this way, but I failed to find any explicit statement about this from Microsoft.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来从前返回值可能有某种含义(请参阅 SQL 2000 之前的 BOL 返回值文章)在 SQL Server 2000 之前。
我检查了一下是否可以找到这些专门用于 MS SQL 的原始返回代码的列表,并找到了 以下(不过我不知道它的真实性,而且它实际上没有列出这些值)。
因此,在阅读所有这些文章后,@return_status 看起来像是一个在执行存储过程时始终返回的参数(即使您不使用它)。根据 RETURN 在线图书文章返回代码不能为空。
运行以下 T-SQL 肯定会显示这一点,
您
最终会收到答案,因为 @return_status 不能为 null(未设置时为 0,或设置为 NULL)。 。
至于假定的 BOL SQL 7.0 的文章,我的猜测是 Sybase 的旧保留...
Kris
It looks like once upon a time the return value may have meant something (see reference of pre SQL 2000 BOL return value article) prior to SQL Server 2000.
I checked around to see if I could find a listing of these original return codes specifically for MS SQL, and found the following (I don't know its authenticity though, and it doesn't actually list the values).
So, after reading all of these articles it looks like @return_status is a parameter that is ALWAYS returned when a stored procedure is executed (even if you do not use it). According to the RETURN Books online article the return code CANNOT be null.
Running the following T-SQL definitely shows this,
You'll receive
In the end it looks like the answer is because @return_status cannot be null (being 0 when not set, or set to NULL)...
As for the error codes mentioned in the supposed BOL article for SQL 7.0, my guess would be an old hold over from Sybase... Sybase 5.0 Manual
Kris
在 MSDN 上返回
编辑:
链接显示
有人可能会说 no RETURN = RETURN NULL = RETURN 0。但是不会发出警告,因为您尚未运行
RETURN NULL
。预期为零,因为它是一个存储过程。另外,存储过程执行允许
所以必须返回一些东西,因为我们总是期望一个值,而不是 NULL
我已经依赖返回零 12 年了,即使 MSDN 没有说。以及我们更多的人:-)
RETURN on MSDN
Edit:
The link says
One could say that no RETURN = RETURN NULL = RETURN 0. But no warning is issued because you have not run
RETURN NULL
. And zero is expected because it's a stored procedure.Also, stored proc execution allows for
So something must be returned because we always expect a value, never NULL
I've relied on zero being returned for 12 years, even if MSDN doesn't say. As well as many more of us :-)
如果您要在客户端中切换一些逻辑,为什么不返回“0”并使其更明确?
if you are going to switch some logic on that in your client, why not return "0" and make it more explicit?
使用返回代码返回数据在线书籍。
Returning Data by Using a Return Code from Books Online.