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

      • <bdo id='sza4s'></bdo><ul id='sza4s'></ul>
      <tfoot id='sza4s'></tfoot>

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

      1. <legend id='sza4s'><style id='sza4s'><dir id='sza4s'><q id='sza4s'></q></dir></style></legend>
      2. 如何使用存储的 MYSQL 程序的表输出

        How to use Table output from stored MYSQL Procedure(如何使用存储的 MYSQL 程序的表输出)

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

              <tbody id='qIvdR'></tbody>
              <bdo id='qIvdR'></bdo><ul id='qIvdR'></ul>

                  <legend id='qIvdR'><style id='qIvdR'><dir id='qIvdR'><q id='qIvdR'></q></dir></style></legend>
                  <tfoot id='qIvdR'></tfoot>
                  本文介绍了如何使用存储的 MYSQL 程序的表输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我一直在寻找最后一个小时左右,但没有找到这个看似简单的问题的最终答案:

                  I've been looking for the last hour or so and haven't found a conclusive answer to this seemingly simple problem:

                  如何调用存储的 MYSQL 函数/过程并在进一步的 SELECT 查询中使用其输出?

                  虽然这显然行不通,但这正是我想要的:

                  Although this obviously doesn't work, this is the kind of thing I'd like to have:

                  SELECT P.`id` FROM (CALL test_proc()) AS P
                  

                  其中 test_proc() 定义为:

                  Where test_proc() is defined by:

                  DROP PROCEDURE IF EXISTS test_proc;
                  DELIMITER ;;
                  CREATE PROCEDURE test_proc()
                  BEGIN
                      SELECT * FROM `table`;
                  END;;
                  DELIMITER ;
                  

                  举个例子.我也可以使用存储函数.

                  Just as an example. I'd be fine with using a stored function as well.

                  推荐答案

                  这不能直接做,因为存储过程中无界选择的输出是发送给客户端的结果集,但技术上不是表.

                  This can't be done, directly, because the output of an unbounded select in a stored procedure is a result set sent to the client, but not technically a table.

                  解决方法是在为您创建表后让 proc 将数据放入临时表中.过程完成后,此表将仅对您的连接可用.如果其他人同时运行 proc 并且对任何其他连接不可见,则不会导致冲突.

                  The workaround is to let the proc put the data in a temporary table after creating the table for you. This table will be available only to your connection when the procedure finishes. It will not cause a conflict if somebody else runs the proc at the same time and won't be visible to any other connection.

                  将其添加到程序中:

                  DROP TEMPORARY TABLE IF EXISTS foo;
                  CREATE TEMPORARY TABLE foo SELECT ... your existing select query here ...;
                  

                  当你的过程完成时,SELECT * FROM foo; 会给你你从过程中得到的东西.您可以像加入任何表一样加入它.

                  When your procedure finishes, SELECT * FROM foo; will give you what you what you would have gotten from the proc. You can join to it pretty much like any table.

                  完成后,放下它,否则断开连接时它会自行消失.如果您再次运行该 proc,它将被删除并重新创建.

                  When you're done, drop it, or it will go away on its own when you disconnect. If you run the proc again, it will be dropped and recreated.

                  这篇关于如何使用存储的 MYSQL 程序的表输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                  How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                  Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)
                  How to get Top 5 records in SqLite?(如何获得 Sqlite 中的前 5 条记录?)
                  SQL Server SELECT where any column contains #39;x#39;(SQL Server SELECT,其中任何列包含“x)
                  Default row order in SELECT query - SQL Server 2008 vs SQL 2012(SELECT 查询中的默认行顺序 - SQL Server 2008 与 SQL 2012)
                  <i id='qVNv1'><tr id='qVNv1'><dt id='qVNv1'><q id='qVNv1'><span id='qVNv1'><b id='qVNv1'><form id='qVNv1'><ins id='qVNv1'></ins><ul id='qVNv1'></ul><sub id='qVNv1'></sub></form><legend id='qVNv1'></legend><bdo id='qVNv1'><pre id='qVNv1'><center id='qVNv1'></center></pre></bdo></b><th id='qVNv1'></th></span></q></dt></tr></i><div id='qVNv1'><tfoot id='qVNv1'></tfoot><dl id='qVNv1'><fieldset id='qVNv1'></fieldset></dl></div>
                    <tbody id='qVNv1'></tbody>

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

                    <legend id='qVNv1'><style id='qVNv1'><dir id='qVNv1'><q id='qVNv1'></q></dir></style></legend>
                    • <bdo id='qVNv1'></bdo><ul id='qVNv1'></ul>

                    • <tfoot id='qVNv1'></tfoot>