当前位置:Gxlcms > mysql > 如何获取存储过程的返回值和输出值

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

时间:2021-07-01 10:21:17 帮助过:69人阅读

定义如下存储过程: 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

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

人气教程排行