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

    <tfoot id='Kn8dU'></tfoot>

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

      <bdo id='Kn8dU'></bdo><ul id='Kn8dU'></ul>

      1. 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递?

        In MySQL: How to pass a table name as stored procedure and/or function argument?(在 MySQL 中:如何将表名作为存储过程和/或函数参数传递?)
        <tfoot id='ppkTR'></tfoot>

        • <legend id='ppkTR'><style id='ppkTR'><dir id='ppkTR'><q id='ppkTR'></q></dir></style></legend>

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

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

          • <bdo id='ppkTR'></bdo><ul id='ppkTR'></ul>
                1. 本文介绍了在 MySQL 中:如何将表名作为存储过程和/或函数参数传递?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  例如,这不起作用:

                  DELIMITER //
                  CREATE PROCEDURE countRows(tbl_name VARCHAR(40))
                    BEGIN
                      SELECT COUNT(*) as ct FROM tbl_name;
                    END //
                  
                  DELIMITER ;
                  CALL countRows('my_table_name');
                  

                  产生:

                  ERROR 1146 (42S02): Table 'test.tbl_name' doesn't exist
                  

                  但是,这按预期工作:

                  SELECT COUNT(*) as ct FROM my_table_name;
                  

                  在 select 语句中使用参数作为表名需要什么语法?这甚至可能吗?

                  What syntax is required to use an argument as a table name in a select statement? Is this even possible?

                  推荐答案

                  准备好的陈述正是您所需要的.

                  CREATE  PROCEDURE `test1`(IN tab_name VARCHAR(40) )
                  BEGIN
                   SET @t1 =CONCAT('SELECT * FROM ',tab_name );
                   PREPARE stmt3 FROM @t1;
                   EXECUTE stmt3;
                   DEALLOCATE PREPARE stmt3;
                  END $$
                  

                  这篇关于在 MySQL 中:如何将表名作为存储过程和/或函数参数传递?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  • <legend id='mt97t'><style id='mt97t'><dir id='mt97t'><q id='mt97t'></q></dir></style></legend>
                  • <tfoot id='mt97t'></tfoot>

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

                        <tbody id='mt97t'></tbody>

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