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

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

        MySQL 将 EXECUTE 的结果保存在变量中?

        时间:2023-10-26
          <legend id='jVqYI'><style id='jVqYI'><dir id='jVqYI'><q id='jVqYI'></q></dir></style></legend>

              <bdo id='jVqYI'></bdo><ul id='jVqYI'></ul>
                <tbody id='jVqYI'></tbody>
            • <small id='jVqYI'></small><noframes id='jVqYI'>

                1. <i id='jVqYI'><tr id='jVqYI'><dt id='jVqYI'><q id='jVqYI'><span id='jVqYI'><b id='jVqYI'><form id='jVqYI'><ins id='jVqYI'></ins><ul id='jVqYI'></ul><sub id='jVqYI'></sub></form><legend id='jVqYI'></legend><bdo id='jVqYI'><pre id='jVqYI'><center id='jVqYI'></center></pre></bdo></b><th id='jVqYI'></th></span></q></dt></tr></i><div id='jVqYI'><tfoot id='jVqYI'></tfoot><dl id='jVqYI'><fieldset id='jVqYI'></fieldset></dl></div>
                  <tfoot id='jVqYI'></tfoot>
                  本文介绍了MySQL 将 EXECUTE 的结果保存在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将 EXECUTE 语句的结果保存到变量中?类似的东西

                  How do I save the results of EXECUTE statement to a variable? Something like

                  SET a = (EXECUTE stmtl);
                  

                  推荐答案

                  如果你想用准备好的语句来做到这一点,那么你需要在原始语句声明中包含变量赋值.

                  If you want to do this with a prepared statement, then you need to include the variable assignment in the original statement declaration.

                  如果您想使用存储的例程,那就更容易了.可以将存储函数的返回值直接赋值给变量,存储过程支持输出参数.

                  If you want to use a stored routine it's easier. You can assign the return value of a stored function directly to a variable, and stored procedures support out parameters.

                  示例:

                  准备好的声明:

                  PREPARE square_stmt from 'select pow(?,2) into @outvar';
                  set @invar = 1;
                  execute square_stmt using @invar;
                  select @outvar;
                  +---------+
                  | @outvar |
                  +---------+
                  |       1 |
                  +---------+
                  DEALLOCATE PREPARE square_stmt;
                  

                  存储函数:

                  delimiter $$
                  create function square_func(p_input int) returns int
                  begin
                    return pow(p_input,2);
                  end $$
                  delimiter ;
                  
                  set @outvar = square_func(2);
                  select @outvar;
                  +---------+
                  | @outvar |
                  +---------+
                  |       4 |
                  +---------+
                  

                  存储过程:

                  delimiter $$
                  create procedure square_proc(p_input int, p_output int)
                  begin
                    set p_output = pow(p_input,2);
                  end $$
                  delimiter ;
                  
                  set @outvar = square_func(3);
                  call square_proc(2,@outvar);
                  select @outvar;
                  +---------+
                  | @outvar |
                  +---------+
                  |       9 |
                  +---------+
                  

                  这篇关于MySQL 将 EXECUTE 的结果保存在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 存储过程权限 下一篇:执行次数最多的存储过程?

                  相关文章

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

                3. <small id='Tgh3y'></small><noframes id='Tgh3y'>

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