I'd like to build a dynamic IN Statement within a MySQL Stored Proc. I've tried a number of ways but am unable to get something that works. This is the closest I've come to success, but it only process the first value in the list:103.
I would prefer to use a stored proc and not to build this SQL statement completely in the client and then execute it. Does anyone know the general rules for dynamically building SQL statements in a stored procedure, esp in regards to the IN Statement?
call foo2('103,104,105,106');
Here is the stored proc:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE `foo2`(
szList VARCHAR(256)
)
BEGIN
SELECT
E_Id, EX_Value
FROM
E
WHERE
EX_Value IN (szList);
END