Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL Stored Procedured apply filter using IN and the filter value is coming from a parameter

As the title mention, i have a problem to apply simple filter on a query result using the operator (IN) in a MySQL Stored Procedured.

The simple example of the Stored Procedured looking like this

DELIMITER $$
DROP PROCEDURE IF EXISTS `sp_example`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_example`(
    `filter_uid_value` TEXT
)
BEGIN

SELECT
    a.id
    , a.name
    , a.uid
FROM
    employee_example a
WHERE 1=1
    AND a.uid IN (filter_uid_value)

END$$
DELIMITER;

so when i call this stored procedured, for example like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

CALL sp_example("du4jgjVRJGs,oKxU3SzV8CK");

the filter is not apply, i wonder how can fix this

>Solution :

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_example`(
    `filter_uid_value` TEXT
)
SELECT id, name, uid
FROM employee_example
WHERE FIND_IN_SET(uid, filter_uid_value);

DELIMITER not needed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading