How to pass a list of IDs to MySQL stored procedure?

前端 未结 1 1121
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 17:23

I\'m writing a stored procedure which should pass its arguments to IN (..) part of query in the procedure body, like this:

DELIMITER //

CREATE          


        
相关标签:
1条回答
  • 2020-12-14 18:18

    You should be able to use MySQL's FIND_IN_SET() to use the list of ids:

    CREATE PROCEDURE `get_users_per_app` (id_list TEXT)
    BEGIN
        SELECT
            app_id, GROUP_CONCAT(user_id)
        FROM
            app_users
        WHERE
            FIND_IN_SET(app_id, id_list) > 0
        GROUP BY app_id;
        ...
    
    0 讨论(0)
提交回复
热议问题