欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

如何获取存储过程的返回值和输出值

程序员文章站 2022-05-27 16:50:00
...

定义如下存储过程: create PROCEDURE mytest ( @returnval decimal OUTPUT --定义一个输出变量 ) as DECLARE @amount DECIMAL DECLARE mycursor CURSOR FOR SELECT Amount FROM dbo.test --定义一个游标 OPEN mycursor FETCH NEXT FROM mycursor INTO @amou

定义如下存储过程:

create PROCEDURE mytest
(
@returnval decimal OUTPUT --定义一个输出变量
)
as
DECLARE @amount DECIMAL
DECLARE mycursor CURSOR FOR SELECT Amount FROM dbo.test --定义一个游标
OPEN mycursor
FETCH NEXT FROM mycursor INTO @amount
WHILE @@FETCH_STATUS=0
BEGIN
IF(@amount=100)BEGIN
SET @returnval = @amount
END
FETCH NEXT FROM mycursor INTO @amount
END
CLOSE mycursor
DEALLOCATE mycursor
RETURN 1;
GO

执行存储过程获取返回值和输出值:

DECLARE @output DECIMAL
DECLARE @val INT
EXEC @val=mytest @returnval = @output OUTPUT
SELECT @val,@output

,网站空间,香港空间,香港空间