IN()不在mysql存储过程中工作

时间:2012-07-23 07:52:11

标签: mysql stored-procedures

DELIMITER $$

USE `employee`$$

DROP PROCEDURE IF EXISTS `selectemployeebyids`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `selectemployeebyids`(IN empid VARCHAR(100))
BEGIN
    SELECT empname,salary,department from emp where empid IN (empid) ORDER BY empid;
    END$$

DELIMITER ;

任何人都可以帮助我

问候

Manju K

2 个答案:

答案 0 :(得分:2)

经过多次尝试后,我发现IN()取代FIND_IN_SET(),而DELIMITER $$ USE `employee`$$ DROP PROCEDURE IF EXISTS `selectemployeebyids`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `selectemployeebyids`(IN empid VARCHAR(100)) BEGIN SELECT empname,salary,department from emp where empid FIND_IN_SET(empid) ORDER BY empid; END$$ DELIMITER ; 适用于我。

{{1}}

答案 1 :(得分:0)

试试这个

DELIMITER $$ 

USE `employee`$$ 

DROP PROCEDURE IF EXISTS `selectemployeebyids`$$ 

CREATE DEFINER=`root`@`localhost` PROCEDURE `selectemployeebyids`(IN empid_in VARCHAR(100)) 
BEGIN 
    SELECT empname,salary,department from emp 
        where concat(',',empid_in,',') like concat('%,'cast  (empid as varchar(10)),',%')
        ORDER BY empid; 
   END$$ 


 DELIMITER ;