gpt4 book ai didi

sql-server - MSDN关于存储过程默认返回值

转载 作者:行者123 更新时间:2023-12-02 10:56:56 25 4
gpt4 key购买 nike

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

IF someStatement
BEGIN
RETURN 1
END

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

我知道它实际上是这样工作的,但我没有找到微软对此的任何明确声明。

最佳答案

在 SQL Server 2000 之前,返回值似乎曾经有过某种意义(请参阅 SQL 2000 之前的 BOL return value article 的引用)。我四处查看是否可以找到专门针对 MS SQL 的这些原始返回代码的列表,并发现 following (不过我不知道它的真实性,而且它实际上没有列出这些值)。

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

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 肯定会显示这一点,

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

至于所谓的BOL article中提到的错误代码对于 SQL 7.0,我的猜测是 Sybase 的旧版本... Sybase 5.0 Manual

克里斯

关于sql-server - MSDN关于存储过程默认返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2578536/

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