首页 >数据库 >mysql教程 > 如何获取存储过程的返回值和输出值

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原创
2016-06-07 17:45:141736浏览

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

,网站空间,香港空间,香港空间
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn