mysql string into IN Clause 拆分字符串什么的?

mysql string into IN Clause splitting string or something?

我需要编写函数,它将采用像

这样的 ID 字符串

('id1,id2,id3...idN')

然后在子句中传递

此函数的调用类似于 select ('id1,id2,id3...idN')

函数内部是这样的 select

select * from table where id in (@string)

如果我将字符串作为字符串传递,它的无效字符串看起来像 '8409 , 8410, 8414, 8416, 10284, 8408',如何将它作为单独的 ID 传递,而不是作为字符串传递?

如果您的字符串格式类似于 8409 , 8410, 8414, 8416, 10284, 8408,则另一种选择是使用 LIKE:

SELECT * FROM table WHERE CONCAT(',','string of id',',') LIKE CONCAT('%,',id,',%')

FIND_IN_SET() 或许对您也有帮助

SELECT * FROM table WHERE FIND_IN_SET(id,'string of id');