MSDN关于存储过程的默认返回值 [英] MSDN about stored procedure default return value

查看:128
本文介绍了MSDN关于存储过程的默认返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能确切指出MSDN所说的地方吗?如果没有发生错误,每个用户存储过程默认都返回0?换句话说,我可以确定下面是存储过程时给出的示例代码

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

如果someStatement为false并且没有错误发生,应该总是返回零吗?

should always return zero if someStatement is false and no error occurs?

我知道它实际上是以这种方式工作的,但是我未能从Microsoft找到任何明确的声明.

I know that it actually works this way, but I failed to find any explicit statement about this from Microsoft.

推荐答案

似乎从前,返回值可能意味着某些含义(请参阅SQL 2000 BOL之前版本的参考

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).

因此,在阅读所有这些文章之后,看起来@return_status是执行存储过程时始终返回的参数(即使您不使用它也是如此).根据返回的在线书籍,返回码不能为空.

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.

与存储过程一起使用时, RETURN不能返回空值.如果 一个过程试图返回一个空值 值(例如,使用RETURN @status为NULL时的@status), 生成警告消息,并且 返回值为0.

When used with a stored procedure, RETURN cannot return a null value. If a procedure tries to return a null value (for example, using RETURN @status when @status is NULL), a warning message is generated and a value of 0 is returned.

运行以下T-SQL肯定显示了这一点,

Running the following T-SQL definitely shows this,

create Procedure Test
as
begin
DECLARE @RTN integer
Return @RTN
END
GO

Exec Test
GO

Drop Procedure Test
GO

您会收到

The 'Test' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.

最后,答案似乎是因为 @return_status不能为空(未设置为0或设置为NULL)...

In the end it looks like the answer is because @return_status cannot be null (being 0 when not set, or set to NULL)...

关于假定的BOL 有关SQL 7.0的文章,我的猜测可能是Sybase的旧版本...

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

克里斯

这篇关于MSDN关于存储过程的默认返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆