1. <tfoot id='iA3EQ'></tfoot>
  2. <small id='iA3EQ'></small><noframes id='iA3EQ'>

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

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

      正在使用“选择 *"PL/SQL 中的游标被认为是糟糕的编程?

      Is using quot;select *quot; for a cursor in PL/SQL considered bad programming?(正在使用“选择 *PL/SQL 中的游标被认为是糟糕的编程?)

      <small id='71gjw'></small><noframes id='71gjw'>

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

              <tbody id='71gjw'></tbody>

                本文介绍了正在使用“选择 *"PL/SQL 中的游标被认为是糟糕的编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我经常这样使用游标:

                for rec in (select * from MY_TABLE where MY_COND = ITION) loop
                    if rec.FIELD1 = 'something' then
                        do_something();
                    end if;
                
                    if rec.FIELD2 <> 'somethingelse' then
                        blabla();
                    end if;
                end loop;
                

                我的团队领导告诉我不要使用 select * 因为它是糟糕的编程,但我不明白为什么(在这种情况下).

                My team leader told me not to use select * because it is bad programming, but I don't understand why (in this context).

                推荐答案

                在你的代码中使用 select * 就是我所说的惰性编程,有几个讨厌的副作用.您经历这些副作用的程度会有所不同,但绝不会是积极的.

                Using select * in your code is what I would call lazy programming, with several nasty side effects. How much you experience those side effects, will differ, but it's never positive.

                我将使用其他答案中已经提到的一些要点,但可以随意编辑我的答案并添加一些关于使用 select * 的负面观点.

                I'll use some of the points already mentioned in other answers, but feel free to edit my answer and add some more negative points about using select *.

                1. 您从 SQL 引擎向您的代码传送了不必要的数据,这会对性能产生负面影响.

                1. You are shipping more data from the SQL engine to your code than necessary, which has a negative effect on performance.

                您返回的信息需要放在变量中(例如记录变量).这将需要更多的 PGA 内存.

                The information you get back needs to be placed in variables (a record variable for example). This will take more PGA memory than necessary.

                通过使用 select *,您将永远不会单独使用索引来检索所需的信息,您还必须始终访问该表(前提是不存在包含所有列的索引)表).同样,对性能有负面影响.

                By using select * you will never use an index alone to retrieve the wanted information, you'll always have to visit the table as well (provided no index exists which holds all columns of the table). Again, with a negative effect on performance.

                对于维护你的代码的人来说,你的意图是什么不太清楚.他们需要深入研究代码以发现所有出现的记录变量以了解正在检索的内容.

                Less clear for people maintaining your code what your intention is. They need to delve into the code to spot all occurrences of your record variable to know what is being retrieved.

                您不会使用 SQL 函数来执行计算,而是始终依赖 PL/SQL 或 Java 计算.您可能会错过一些重要的 SQL 改进,例如分析函数、模型子句、递归子查询分解等.

                You will not use SQL functions to perform calculations, but always rely on PL/SQL or Java calculations. You are possibly missing out on some great SQL improvements like analytic functions, model clause, recursive subquery factoring and the like.

                从 Oracle11 开始,在列级别跟踪依赖关系,这意味着当您使用 select * 时,您的代码在数据字典中被标记为依赖于所有列"那张桌子.当其中一列发生问题时,您的程序将失效.因此,使用 select * 意味着您的代码将比必要的更频繁地失效.

                From Oracle11 onwards, dependencies are being tracked on column level, meaning that when you use select *, your code is being marked in the data dictionary as "dependent on all columns" of that table. Your procedure will be invalidated when something happens to one of those columns. So using select * means your code will be invalidated more often than necessary.

                同样,请随意添加您自己的分数.

                Again, feel free to add your own points.

                这篇关于正在使用“选择 *"PL/SQL 中的游标被认为是糟糕的编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to save a Google maps overlay shape in the database?(如何在数据库中保存谷歌地图叠加形状?)
                Is there a performance hit using decimal data types (MySQL / Postgres)(使用十进制数据类型(MySQL/Postgres)是否会影响性能)
                How to reduce size of SQL Server table that grew from a datatype change(如何减少因数据类型更改而增长的 SQL Server 表的大小)
                Comparison of database column types in MySQL, PostgreSQL, and SQLite? (Cross-Mapping)(MySQL、PostgreSQL、SQLite中数据库列类型的比较?(交叉映射))
                Common MySQL fields and their appropriate data types(常见的 MySQL 字段及其相应的数据类型)
                How to call Oracle function or stored procedure using spring persistence framework?(如何使用 Spring 持久化框架调用 Oracle 函数或存储过程?)

                  <tbody id='dqftE'></tbody>

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

                      1. <small id='dqftE'></small><noframes id='dqftE'>

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