How to search a string within a dynamic list of string in MYSQL Stored Procedure

In my database I’m searching for a list of ID’s like this:

SELECT * from testcase where id in ('658', '659');

But how can I make this into a stored procedure, which can take multiple id’s?

In this example I have only '658', '659' but this could be more/less.

I made a stored procedure, but either it failes because I have two id’s or more, and if I make it into a single string like this, '658, 659', then it only find the results from 658:

CREATE DEFINER=`edmetrics`@`%` PROCEDURE `GetCaseFromStrList`(CaseIDs varchar(300))
BEGIN
IF CaseIDs != 0 OR CaseIDs IS NOT NULL THEN
        Select testcase.id, testcase.TestCaseName
      From testcase
      Where testcase.id in (CaseIDs);
    END IF;
END

Is there a way to make a call like this, with multiple X amount of id’s?

CALL database.GetCaseFromStrList(658 , 659);

EDIT – more info

Was told I cold look at this solution, but it’s not 100% the thing im looking for: StackOverflow Link

But I will show an example with pictures

When I write this SQL: SELECT * from testcase where id in ('658', '659'); I get the following result

Table result

If I try to implement the linked solution with FIND_IN_SET() in my stored procedure I have this:

CREATE DEFINER=`edmetrics`@`%` PROCEDURE `GetCaseFromStrList`(CaseIDs varchar(300))
BEGIN
SET @idCaseIDs = CaseIDs;
IF CaseIDs != 0 OR CaseIDs IS NOT NULL THEN
        Select testcase.id, testcase.TestCaseName
      From testcase
      WHERE FIND_IN_SET(testcase.id, @idCaseIDs);
    END IF;
END

But if I use a string with all the ID’s in it, and make a call like this: CALL testreporting.GetCaseFromStrList('658, 659');

I get the following result

Table result from stored procedure

And in that result I’m missing the ID 659.

and remember this is with two ID’s, but I can have X amount of ID’s not only two.

Answer

fIND_IN_SET works just fine, see example

CREATE TABLE testcase(id int,TestCaseName varchar(50) )
INSERT INTO testcase VALUES (658,'test1'),(659,'test2')
CREATE  PROCEDURE `GetCaseFromStrList`(_CaseIDs varchar(300))
BEGIN

IF _CaseIDs != 0 OR _CaseIDs IS NOT NULL THEN
        Select testcase.id, testcase.TestCaseName
      From testcase
      WHERE FIND_IN_SET(testcase.id, _CaseIDs);
    END IF;
END
CALL GetCaseFromStrList('658,659')
 id | TestCaseName
--: | :-----------
658 | test1       
659 | test2       

✓

db<>fiddle here