<tfoot id='6A6sK'></tfoot>
        <bdo id='6A6sK'></bdo><ul id='6A6sK'></ul>

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

        <small id='6A6sK'></small><noframes id='6A6sK'>

        <legend id='6A6sK'><style id='6A6sK'><dir id='6A6sK'><q id='6A6sK'></q></dir></style></legend>

        在程序中将提交放在 DML 之后有什么影响?

        时间:2023-09-19
        <legend id='ITRFb'><style id='ITRFb'><dir id='ITRFb'><q id='ITRFb'></q></dir></style></legend>

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

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

                    <tbody id='ITRFb'></tbody>
                  本文介绍了在程序中将提交放在 DML 之后有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个包中创建了一个程序,该程序在表中执行插入/删除操作,并在成功事务后提交.

                  像这样:

                  创建或替换包pac是程序 pr_test(emp_id 编号)是开始-- 一些代码如果有那么插入别的删除犯罪;结束 pr_test;结束 pac ;

                  我应该以 AUTONOMOUS_TRANSACTION 的身份进行此交易吗?在程序中放置这样的提交有什么影响?

                  解决方案

                  把这样的commit放在程序里有什么作用?

                  Oracle 文档 描述了COMMIT 为:

                  <块引用>

                  目的

                  使用 COMMIT 语句来结束您当前的事务并使永久事务中执行的所有更改.交易是一个Oracle 数据库将其视为单个 SQL 语句的序列单元.此语句还会删除事务中的所有保存点并释放事务锁.

                  如果你有三个 PROCEDURE 并且每个都包含一个 COMMIT 语句,那么你不能运行所有三个然后,如果在后一个中发生异常,ROLLBACK 它们全部,因为前两个的更改已经 COMMITted.

                  作为一般规则,您应该不要PROCEDUREFUNCTION 中使用 COMMIT 但应该保留它由调用者COMMIT事务,以便他们可以将多个操作捆绑在一起.

                  当然,有些用例您会想要违反此规则,但您应该分别考虑每种情况,并在违反此规则之前花时间充分了解您的业务逻辑,以便您知道什么是 COMMIT在每个实例中都进行了标记.

                  <块引用>

                  我应该以AUTONOMOUS_TRANSACTION的身份进行这笔交易吗?

                  一个用例是记录 - 您可能有一个 PROCEDURE 调用另一个 PROCEDURE 来记录用户的操作,无论初始操作是成功还是失败想要保留操作的日志并确保日志是 COMMITted.在这种情况下,日志记录 PROCEDURE 应该是一个 AUTONOMOUS_TRANSACTION 并包含一个 COMMIT 语句,而调用语句应该(可能)两者都没有.>

                  因此,如果一个 PROCEDURECOMMIT 始终是必需的,并且与调用者 COMMIT 的其他数据是否无关,则使 PROCEDURE 一个 AUTONOMOUS_TRANSACTION.如果 PROCEDURE 可以捆绑在一起,然后 ROLLBACK 作为一个组,那么您不想让它们成为 AUTONOMOUS_TRANSACTION.

                  I have created a procedure in a package which is doing insert/delete in the table and after successful transaction, commit is done.

                  like this:

                  create or replace package pac is    
                  procedure pr_test(emp_id number)
                  is
                  begin
                  -- some code
                  if something then
                    insert
                  else
                    delete
                  
                  commit;
                  end pr_test;
                  end pac ;
                  

                  Should I make this transaction as AUTONOMOUS_TRANSACTION? What is the effect of placing the commit like this in program?

                  解决方案

                  What is the effect of placing the commit like this in program?

                  The Oracle Documentation describes COMMIT as:

                  Purpose

                  Use the COMMIT statement to end your current transaction and make permanent all changes performed in the transaction. A transaction is a sequence of SQL statements that Oracle Database treats as a single unit. This statement also erases all savepoints in the transaction and releases transaction locks.

                  If you have three PROCEDURE and each one contains a COMMIT statement then you cannot run all three then, if an exception occurs in a latter one, ROLLBACK them all as the changes from the first two will already be COMMITted.

                  As a general rule, you should not use COMMIT in a PROCEDURE or FUNCTION but should leave it up to the caller to COMMIT the transaction so they can bundle multiple actions together.

                  There are, of course, use cases where you will want to violate this rule but you should consider each case separately and take time to fully understand your business logic before you break this rule so you know what is COMMITted in each instance.

                  Should I make this transaction as AUTONOMOUS_TRANSACTION?

                  One use-case is logging - you may have a PROCEDURE which calls another PROCEDURE to log the user's actions and, regardless of whether the initial action succeeds or fails you want to keep a log of the action and ensure that log is COMMITted. In this case, the logging PROCEDURE should be an AUTONOMOUS_TRANSACTION and contain a COMMIT statement and the calling statement should (probably) have neither.

                  So, if the COMMIT of one PROCEDURE is always required and is independent of whether the caller COMMITs other data then make the PROCEDURE an AUTONOMOUS_TRANSACTION. If the PROCEDUREs can be bundled together and then ROLLBACK as a group then you do not want to make them AUTONOMOUS_TRANSACTIONs.

                  这篇关于在程序中将提交放在 DML 之后有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么我似乎不能强制 Oracle 11g 为单个 SQL 查询消耗更多 CPU 下一篇:我们可以在 PL/SQL 中使用线程吗?

                  相关文章

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

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

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