如何从单个选择查询来自存储过程设置多个输出变量值

时间:2018-04-04 07:56:30

标签: mysql stored-procedures

CREATE DEFINER=`root`@`%` PROCEDURE `sp_search_dir`(
IN name varchar(50),
OUT employeeId varchar(50) ,
OUT employeeName varchar(50)
)

BEGIN


 -- First : working ---
 SELECT  EAE.id INTO employeeId , EAE.name INTO employeeName 
 FROM employeesDB.employee AS EAE
 WHERE EAE.f_name  LIKE CONCAT('%', name , '%');


 -- Second Working ---
 SELECT  EAE.id INTO employeeId , EAE.name INTO employeeName 
 FROM employeesDB.employee AS EAE
 WHERE EAE.f_name  LIKE CONCAT('%', name , '%');

 -- Third  NOT working  getting syntax ERROR why i am not able to set two 
 OUT variable in one select  

 SELECT  
 EAE.id INTO employeeId ,
 EAE.name INTO employeeName 
 FROM employeesDB.employee AS EAE
 WHERE EAE.f_name  LIKE CONCAT('%', name , '%');

 END

我无法在store-procedure中的单个选择查询中设置多个输出值以获取id和employeename我必须调用两个选择查询我想在一个查询中提取结果..

1 个答案:

答案 0 :(得分:1)

您的SELECT ... INTO语法错误。

必须是:

SELECT EAE.id, EAE.name
     INTO employeeId, employeeName 
 FROM employeesDB.employee AS EAE
 WHERE EAE.f_name LIKE CONCAT('%', name , '%');