我想为选择查询创建一个过程,其中where子句将具有子句。我创建了一个像下面的过程一样,它不工作 -
CREATE DEFINER = `root`@`localhost` PROCEDURE `agentin` ( IN `code` VARCHAR( 100 ) ) NOT DETERMINISTIC NO SQL SQL SECURITY DEFINER
BEGIN
SELECT * FROM AgentInformation WHERE AgentCode IN (code);
END
将" in"子句值类似于 -> in('cg001','cg002')
我得到了无效的值,而phpmyadmin的查询为
SET @p0 = '''CG001'',''CG002''';
致电agentin
(@P0);
请为此提供帮助,谢谢
这是一个示例 -
DELIMITER $$
CREATE PROCEDURE procedure1(IN id_param VARCHAR(255))
BEGIN
SET @sql = CONCAT('SELECT * FROM table WHERE id IN (', id_param, ')');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;
SET @id = '1,2,3,4,5';
CALL procedure1(@id);