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

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

    2. <small id='waDs0'></small><noframes id='waDs0'>

        <tfoot id='waDs0'></tfoot>

        存储过程中的 MySQL PREPARE 语句

        MySQL PREPARE statement in stored procedures(存储过程中的 MySQL PREPARE 语句)

        <tfoot id='7Dc5M'></tfoot>
          <legend id='7Dc5M'><style id='7Dc5M'><dir id='7Dc5M'><q id='7Dc5M'></q></dir></style></legend>

          <small id='7Dc5M'></small><noframes id='7Dc5M'>

                <tbody id='7Dc5M'></tbody>
                <bdo id='7Dc5M'></bdo><ul id='7Dc5M'></ul>
                  <i id='7Dc5M'><tr id='7Dc5M'><dt id='7Dc5M'><q id='7Dc5M'><span id='7Dc5M'><b id='7Dc5M'><form id='7Dc5M'><ins id='7Dc5M'></ins><ul id='7Dc5M'></ul><sub id='7Dc5M'></sub></form><legend id='7Dc5M'></legend><bdo id='7Dc5M'><pre id='7Dc5M'><center id='7Dc5M'></center></pre></bdo></b><th id='7Dc5M'></th></span></q></dt></tr></i><div id='7Dc5M'><tfoot id='7Dc5M'></tfoot><dl id='7Dc5M'><fieldset id='7Dc5M'></fieldset></dl></div>
                  本文介绍了存储过程中的 MySQL PREPARE 语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有这个 sql 文件:

                  I have this sql file:

                  USE mydb;
                  
                  DROP PROCEDURE IF EXISTS execSql;
                  DELIMITER //
                  CREATE PROCEDURE execSql (
                                       IN sqlq VARCHAR(5000)
                                        ) COMMENT 'Executes the statement'
                  BEGIN
                    PREPARE stmt FROM sqlq;
                    EXECUTE stmt;
                    DEALLOCATE PREPARE stmt;
                  END //
                  DELIMITER ;          
                  

                  当我尝试运行它时

                  # cat file.sql |mysql -p

                  # cat file.sql | mysql -p

                  我明白

                  ERROR 1064 (42000) at line 6: You have an error in your SQL syntax; check the manual
                  that corresponds to your MySQL server version for the right syntax to use near 'sqlq;
                    EXECUTE stmt;
                    DEALLOCATE PREPARE stmt;
                    END' at line 5
                  

                  我做错了什么?

                  推荐答案

                  您只能准备和执行 字符串文字用户定义的变量,包含语句的文本.

                  You can only prepare and execute SQL that's a string literal or a user-defined variable that contains the text of the statement.

                  试试这个:

                  USE mydb;
                  
                  DROP PROCEDURE IF EXISTS execSql;
                  DELIMITER //
                  
                  CREATE PROCEDURE execSql (IN sqlq VARCHAR(5000)) COMMENT 'Executes the statement'
                  BEGIN
                    SET @sqlv = sqlq;
                    PREPARE stmt FROM @sqlv;
                    EXECUTE stmt;
                    DEALLOCATE PREPARE stmt;
                  END //
                  
                  DELIMITER ;      
                  

                  这篇关于存储过程中的 MySQL PREPARE 语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Accessing another user#39;s table within an Oracle Stored Procedure(在 Oracle 存储过程中访问另一个用户的表)
                  How to View Oracle Stored Procedure using SQLPlus?(如何使用 SQLPlus 查看 Oracle 存储过程?)
                  How to Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  Set the variable result, from query(设置变量结果,来自查询)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)

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

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

                  • <bdo id='TjvUQ'></bdo><ul id='TjvUQ'></ul>

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

                              <tbody id='TjvUQ'></tbody>