Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-07 17:45:14
Original
1666 people have browsed it

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

,网站空间,香港空间,香港空间
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!