如何获取存储过程的返回值和输出值
程序员文章站
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