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

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

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

      <tfoot id='pVs7X'></tfoot>

      <legend id='pVs7X'><style id='pVs7X'><dir id='pVs7X'><q id='pVs7X'></q></dir></style></legend>
    1. 我的 SQL 动态查询执行并将输出输出到存储过程中的变量中

      时间:2023-06-01

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

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

                <tbody id='fwvbv'></tbody>

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

                本文介绍了我的 SQL 动态查询执行并将输出输出到存储过程中的变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在我的 sql 存储过程中生成了一个动态查询.我想将此查询的结果放入一个 out 参数中.如何做到这一点?

                I generate a dynamic query in My sql Stored procedure. I wanna get the result of this query into a out parameter. How to do this ?

                CREATE PROCEDURE 'searchInvoice'
                (
                  OUT numOfRecords INT
                )
                BEGIN
                  DECLARE query1 TEXT; 
                  DECLARE query2 TEXT; 
                
                 SET query1 = 'SELECT COUNT(*) bla bla bla.....'; 
                 // Query1 to select the count of matching tuples..
                
                 SET query2 = 'SELECT * from bla bla bla....';
                 // Query2 to select original records...
                
                 // later part of this both queries generate dynamically according to some IN parameters..
                
                 // now I wanna assign the output of the query1 into numOfRecords 
                 // and I wanna execute the query2 as well.. like this
                
                    SET @Sql = query2;        
                    PREPARE STMT FROM @Sql; 
                    EXECUTE STMT; 
                    DEALLOCATE PREPARE STMT;
                
                 // output of the query2 can be read in PHP
                
                END
                

                如何将query1的输出放入OUT参数(numOfRecords)??

                How to get the output of the query1 into OUT parameter(numOfRecords ) ??

                推荐答案

                看看这个例子 -

                CREATE TABLE table1(
                  column1 VARCHAR(255) DEFAULT NULL,
                  column2 VARCHAR(255) DEFAULT NULL,
                  column3 VARCHAR(255) DEFAULT NULL
                );
                
                INSERT INTO table1 VALUES 
                  ('1', 'value1', 'value2'),
                  ('2', 'value3', 'value4');
                
                DELIMITER $$
                CREATE PROCEDURE procedure1(IN Param1 VARCHAR(255), OUT Param2 VARCHAR(255), OUT Param3 VARCHAR(255))
                BEGIN
                  SET @c2 = '';
                  SET @c3 = '';
                  SET @query = 'SELECT column2, column3 INTO @c2, @c3 FROM table1 WHERE column1 = ?';
                  PREPARE stmt FROM @query;
                  SET @c1 = Param1;
                  EXECUTE stmt USING @c1;
                  DEALLOCATE PREPARE stmt;
                  SET Param2 = @c2;
                  SET Param3 = @c3;
                END$$
                DELIMITER ;
                
                -- Call procedure and use variables
                SET @Param1 = 2;
                SET @Param2 = '';
                SET @Param3 = '';
                CALL procedure1(@Param1, @Param2, @Param3);
                SELECT @Param2, @Param3;
                +---------+---------+
                | @Param2 | @Param3 |
                +---------+---------+
                | value3  | value4  |
                +---------+---------+
                

                这篇关于我的 SQL 动态查询执行并将输出输出到存储过程中的变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:“193:%1 不是有效的 Win32 应用程序"新 Rails 应用程序的错误 下一篇:将 RMySQL 包添加到 R 失败(在 Windows 上)?

                相关文章

                  1. <legend id='ZbssX'><style id='ZbssX'><dir id='ZbssX'><q id='ZbssX'></q></dir></style></legend>

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

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

                    <tfoot id='ZbssX'></tfoot>