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

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

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

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

        设置变量结果,来自查询

        Set the variable result, from query(设置变量结果,来自查询)
      1. <tfoot id='HLy48'></tfoot>
      2. <small id='HLy48'></small><noframes id='HLy48'>

      3. <legend id='HLy48'><style id='HLy48'><dir id='HLy48'><q id='HLy48'></q></dir></style></legend>

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

              <tbody id='HLy48'></tbody>
              <bdo id='HLy48'></bdo><ul id='HLy48'></ul>
                1. 本文介绍了设置变量结果,来自查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我创建保存的过程时,我可以创建一些变量是吗?例如:

                  When I create the saved procedure, i can create some variable yes? for example:

                  CREATE PROCEDURE `some_proc` ()  
                  BEGIN  
                  
                     DECLARE some_var INT; 
                     SET some_var = 3;
                  ....
                  

                  问题:但是如何从查询中设置变量结果,这就是如何制作这样的:

                  QUESTION: but how to set variable result from the query, that is how to make some like this:

                  DECLARE some_var INT;
                  SET some_var = SELECT COUNT(*) FROM mytable ;
                  

                  ?

                  推荐答案

                  有多种方法可以做到这一点.

                  There are multiple ways to do this.

                  您可以使用子查询:

                  SET @some_var = (SELECT COUNT(*) FROM mytable);
                  

                  (就像你原来的一样,只需在查询周围添加括号)

                  (like your original, just add parenthesis around the query)

                  或使用 SELECT INTO 语法来分配多个值:

                  or use the SELECT INTO syntax to assign multiple values:

                  SELECT COUNT(*), MAX(col)
                  INTO   @some_var, @some_other_var
                  FROM   tab;
                  

                  子查询语法稍快(我不知道为什么),但只能分配一个值.select into 语法允许您一次设置多个值,因此如果您需要从查询中获取多个值,您应该这样做,而不是为每个变量一次又一次地执行查询.

                  The sub query syntax is slightly faster (I don't know why) but only works to assign a single value. The select into syntax allows you to set multiple values at once, so if you need to grab multiple values from the query you should do that rather than execute the query again and again for each variable.

                  最后,如果您的查询返回的不是单行而是结果集,您可以使用 光标.

                  Finally, if your query returns not a single row but a result set, you can use a cursor.

                  这篇关于设置变量结果,来自查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 Pass Java List of Objects to Oracle Stored Procedure Using MyBatis?(如何使用 MyBatis 将 Java 对象列表传递给 Oracle 存储过程?)
                  What is dynamic SQL?(什么是动态 SQL?)
                  Mysql - How to quit/exit from stored procedure(Mysql - 如何退出/退出存储过程)

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

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

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

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