Is a return value of 0 always a success in stored procedures?

*爱你&永不变心* 提交于 2020-02-03 03:16:12

问题


If a stored procedure returns a value of zero, does that always mean it was run successfully? I am using MS SQL Server 2008.


回答1:


No, you can return something yourself

example

CREATE PROC pr_test AS 
SELECT 1/0

RETURN 0
GO

Now run it

DECLARE @i INT
exec @i = pr_test

SELECT @i  -- will be 0

DROP PROC pr_test

Now let's do it again without the return statement

CREATE PROC pr_test2 AS 
SELECT 1/0

GO

DECLARE @i INT
exec @i = pr_test2

SELECT @i  -- will be - 6

Better to use an output parameter to pass back statuses and or messages




回答2:


An @@ERROR return value of "zero" indicates that your procedure completed without any errors.

Of course, that doesn't mean that it did what you wanted it to...

Can you be more specific about what you're looking at?




回答3:


You can use the Return word to return any integer value from a Stored Procedure. That means that zero does not mean that the stored procedure was executed successfully.



来源:https://stackoverflow.com/questions/6034746/is-a-return-value-of-0-always-a-success-in-stored-procedures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!