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

        <tfoot id='agAXB'></tfoot>

      1. <legend id='agAXB'><style id='agAXB'><dir id='agAXB'><q id='agAXB'></q></dir></style></legend>
        • <bdo id='agAXB'></bdo><ul id='agAXB'></ul>

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

        游标中的 PL/SQL 变量是否与绑定参数有效相同?

        时间:2023-11-02
        • <bdo id='UMui4'></bdo><ul id='UMui4'></ul>
          • <tfoot id='UMui4'></tfoot>

                <tbody id='UMui4'></tbody>
            • <legend id='UMui4'><style id='UMui4'><dir id='UMui4'><q id='UMui4'></q></dir></style></legend>

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

                  <i id='UMui4'><tr id='UMui4'><dt id='UMui4'><q id='UMui4'><span id='UMui4'><b id='UMui4'><form id='UMui4'><ins id='UMui4'></ins><ul id='UMui4'></ul><sub id='UMui4'></sub></form><legend id='UMui4'></legend><bdo id='UMui4'><pre id='UMui4'><center id='UMui4'></center></pre></bdo></b><th id='UMui4'></th></span></q></dt></tr></i><div id='UMui4'><tfoot id='UMui4'></tfoot><dl id='UMui4'><fieldset id='UMui4'></fieldset></dl></div>
                  本文介绍了游标中的 PL/SQL 变量是否与绑定参数有效相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我听说使用绑定变量(可以)更有效,因为对于具有不同绑定值的后续调用,查询本身仍然相同,因此不再需要对其进行解析.

                  I've heard that using bind variables is (can be) more efficient, because for subsequent calls with a different bind value, the query itself is still the same, so it doesn't need to be parsed anymore.

                  我理解为什么固定值会出现这种情况.在下面的游标中,该值固定为 1.如果我有一个相同的不同游标,除了 1 变为 2,这是一个不同的查询.到目前为止清除.

                  I understand why this is the case for fixed values. In the cursor below, the value is fixed on 1. If I have a different cursor that is the same, except the 1 becomes 2, it is a diffent query. Clear so far.

                  declare
                    cursor C_CURSOR is 
                      select * from TESTTABLE pt where pt.ID = 1;
                  

                  但我想知道在游标内使用 PL/SQL 变量时是否也是这种情况.它们是否被扩展为一个固定值,或者它们是否被解释为绑定变量.

                  But I wondered if this is also the case when using PL/SQL variables inside the cursor. Are they expanded as if it's a fixed value, or are they interpreted as bind variables.

                  我进行了广泛的搜索,但到处都可以找到关于文字的示例,就像上面的例子一样,但没有明确解释 PL/SQL 变量的使用.

                  I've searched far and wide, but everywhere I find examples about literals, as in the case above, but no clear explanation about the use of PL/SQL variables.

                  换句话说,在下面的两个片段中,第二个可能更有效,还是本质上相同?

                  In other words, of the two snippets below, is the second one potentially more efficient, or are they essentially the same?

                  直接在游标中使用 PL/SQL 变量:

                  With a PL/SQL variable directly in the cursor:

                  declare
                    V_TEST integer := 1;
                  
                    cursor C_CURSOR is 
                      select * 
                      from 
                        TESTTABLE pt
                      where
                        pt.ID = V_TEST;
                  
                  begin
                    for r in C_CURSOR loop
                      null;
                    end loop;
                  end;
                  

                  使用绑定变量:

                  declare
                    V_TEST int := 1;
                  
                    cursor C_CURSOR(B_TEST int) is 
                      select * 
                      from 
                        TESTTABLE pt
                      where
                        pt.ID = B_TEST;
                  
                  begin
                    for r in C_CURSOR(V_TEST) loop
                      null;
                    end loop;
                  end;
                  

                  推荐答案

                  首先,好问题.

                  我想引用一下:

                  对 PL/SQL 变量的每个引用实际上都是一个绑定变量.

                  Every reference to a PL/SQL variable is in fact a bind variable.

                  话虽如此,

                  PL/SQL 本身处理了与绑定变量有关的大部分问题,以至于您编写的大多数代码已经在您不知情的情况下使用了绑定变量.以下面的 PL/SQL 代码为例:

                  PL/SQL itself takes care of most of the issues to do with bind variables, to the point where most code that you write already uses bind variables without you knowing. Take, for example, the following bit of PL/SQL:

                  create or replace procedure dsal(p_empno in number)
                  as
                    begin
                      update emp
                      set sal=sal*2
                      where empno = p_empno;
                      commit;
                    end;
                  /
                  

                  现在您可能认为必须用绑定变量替换 p_empno.然而,好消息是每个对 PL/SQL 变量的引用实际上都是一个绑定变量.

                  Now you might be thinking that you've got to replace the p_empno with a bind variable. However, the good news is that every reference to a PL/SQL variable is in fact a bind variable.

                  来源

                  这篇关于游标中的 PL/SQL 变量是否与绑定参数有效相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Oracle 存储过程中访问另一个用户的表 下一篇:PL/SQL 是否具有与 Java 等效的 StringTokenizer?

                  相关文章

                  • <bdo id='4Eafg'></bdo><ul id='4Eafg'></ul>

                    <legend id='4Eafg'><style id='4Eafg'><dir id='4Eafg'><q id='4Eafg'></q></dir></style></legend>
                    <tfoot id='4Eafg'></tfoot>
                  1. <small id='4Eafg'></small><noframes id='4Eafg'>

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