如何在mysql存储过程中返回输出参数

vzgqcmou  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(390)

我想从存储过程返回一个输出参数。我已经写了下面的查询,但是输出参数给出的是空值

CREATE DEFINER=`root`@`%` PROCEDURE `GetVendorSpecificReport`(
  startdate DATE,
  enddate DATE,
   vendorname  varchar(50),
out vendoremail varchar(50)
)
BEGIN

SELECT email into vendoremail from user where FirstName=@vendorname;

select distinct concat(u.Firstname, ' ', u.Lastname) as Name, 
u.FirstName,  t.subtask, u.NTName, from user U, task t, groupuser g, `group` g1
where  U.idUser= t.userid and g.userid= U.idUser
and g1.name=vendorname and date >= startdate and date <= enddate
order by  date,u.FirstName asc;

END $$

DELIMITER ;

有人能帮我吗?

gmxoilav

gmxoilav1#

您应该在代码中将“@vendorname”替换为“vendorname”。您可以尝试简化代码或创建另一个非常简单的测试sp进行检查。
以下是在我的系统中运行良好的简单sp:

DELIMITER $$
CREATE PROCEDURE `z`(
    IN `a` INT,
    OUT `b` INT
)
BEGIN
    SELECT a + 1 into b;
END;
$$

DELIMITER ;

CALL z(1, @x);
SELECT @x;

相关问题