• <small id='suBix'></small><noframes id='suBix'>

    <legend id='suBix'><style id='suBix'><dir id='suBix'><q id='suBix'></q></dir></style></legend><tfoot id='suBix'></tfoot>
        <bdo id='suBix'></bdo><ul id='suBix'></ul>
      <i id='suBix'><tr id='suBix'><dt id='suBix'><q id='suBix'><span id='suBix'><b id='suBix'><form id='suBix'><ins id='suBix'></ins><ul id='suBix'></ul><sub id='suBix'></sub></form><legend id='suBix'></legend><bdo id='suBix'><pre id='suBix'><center id='suBix'></center></pre></bdo></b><th id='suBix'></th></span></q></dt></tr></i><div id='suBix'><tfoot id='suBix'></tfoot><dl id='suBix'><fieldset id='suBix'></fieldset></dl></div>

      1. 如何将 ID 列表传递给 MySQL 存储过程?

        How to pass a list of IDs to MySQL stored procedure?(如何将 ID 列表传递给 MySQL 存储过程?)

          • <bdo id='MP6Qa'></bdo><ul id='MP6Qa'></ul>
            <i id='MP6Qa'><tr id='MP6Qa'><dt id='MP6Qa'><q id='MP6Qa'><span id='MP6Qa'><b id='MP6Qa'><form id='MP6Qa'><ins id='MP6Qa'></ins><ul id='MP6Qa'></ul><sub id='MP6Qa'></sub></form><legend id='MP6Qa'></legend><bdo id='MP6Qa'><pre id='MP6Qa'><center id='MP6Qa'></center></pre></bdo></b><th id='MP6Qa'></th></span></q></dt></tr></i><div id='MP6Qa'><tfoot id='MP6Qa'></tfoot><dl id='MP6Qa'><fieldset id='MP6Qa'></fieldset></dl></div>
          • <tfoot id='MP6Qa'></tfoot>

                <tbody id='MP6Qa'></tbody>

              <small id='MP6Qa'></small><noframes id='MP6Qa'>

            1. <legend id='MP6Qa'><style id='MP6Qa'><dir id='MP6Qa'><q id='MP6Qa'></q></dir></style></legend>
                1. 本文介绍了如何将 ID 列表传递给 MySQL 存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写一个存储过程,它应该将其参数传递给过程主体中查询的 IN (..) 部分,如下所示:

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

                  DELIMITER //
                  
                  CREATE PROCEDURE `get_users_per_app` (id_list TEXT)
                  BEGIN
                      SELECT app_id, GROUP_CONCAT(user_id) FROM app_users WHERE app_id IN (id_list) GROUP BY app_id;
                  END//
                  
                  DELIMITER ;
                  

                  这显然不起作用,因为当我传递一个文本值时,id_list 被插入为一个整数,并且只有第一个 ID 被考虑并用于 IN()IN()代码>条件.

                  This, obviously, doesn't work because when I pass a textual value, id_list is interpolated as an integer and only first ID is considered and used inside of IN() condition.

                  我意识到可以用包含的查询代替这种特定类型的过程,但我认为我的问题仍然存在 - 如果我需要传递此类数据怎么办?

                  I realize that this particular type of procedure could be instead replaced by the contained query, but I think that my question still stands - what if I needed to pass this kind of data?

                  我也意识到这种查询方法可能不被视为最佳实践,但在我的用例中,它实际上比返回 ID-ID 对的平面列表要好..

                  推荐答案

                  你应该能够使用 MySQL 的 FIND_IN_SET() 使用 id 列表:

                  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;
                      ...
                  

                  这篇关于如何将 ID 列表传递给 MySQL 存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)

                    <bdo id='rBsue'></bdo><ul id='rBsue'></ul>
                            <tbody id='rBsue'></tbody>
                        1. <small id='rBsue'></small><noframes id='rBsue'>

                          1. <tfoot id='rBsue'></tfoot>
                            <i id='rBsue'><tr id='rBsue'><dt id='rBsue'><q id='rBsue'><span id='rBsue'><b id='rBsue'><form id='rBsue'><ins id='rBsue'></ins><ul id='rBsue'></ul><sub id='rBsue'></sub></form><legend id='rBsue'></legend><bdo id='rBsue'><pre id='rBsue'><center id='rBsue'></center></pre></bdo></b><th id='rBsue'></th></span></q></dt></tr></i><div id='rBsue'><tfoot id='rBsue'></tfoot><dl id='rBsue'><fieldset id='rBsue'></fieldset></dl></div>

                            <legend id='rBsue'><style id='rBsue'><dir id='rBsue'><q id='rBsue'></q></dir></style></legend>