<small id='3Qj0z'></small><noframes id='3Qj0z'>

    • <bdo id='3Qj0z'></bdo><ul id='3Qj0z'></ul>

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

    <legend id='3Qj0z'><style id='3Qj0z'><dir id='3Qj0z'><q id='3Qj0z'></q></dir></style></legend>
    1. 触发器中的 pragma 自治事务

      pragma autonomous_transaction in a trigger(触发器中的 pragma 自治事务)
      <legend id='JxEcX'><style id='JxEcX'><dir id='JxEcX'><q id='JxEcX'></q></dir></style></legend>
        <bdo id='JxEcX'></bdo><ul id='JxEcX'></ul>

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

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

                本文介绍了触发器中的 pragma 自治事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我在一个表上写了一个触发器,它根据条件从另一个表中删除数据.触发器具有编译指示 Autonomous_transaction,并且触发器按预期工作.但是,我想知道将来是否会出现任何问题,比如数据是否由多个用户/来源同时插入等等......有什么建议吗?

                I have written a trigger on one table which deletes data from other table upon a condition. The trigger has pragma autonomous_transaction, and trigger works as intended. However, I do wonder if there can be any problems in future, say if data is inserted by multiple users/sources at the same time etc...Any suggestions?

                源表t1:

                --------------------------------------------
                | user_id | auth_name1 | auth_name2 | data |
                --------------------------------------------
                |  1      |  Name1     |  Name2      | d1  |
                |  2      |  Name3     |  Name4      | d2  |
                |  3      |  Name5     |  Name1      | d3  |
                --------------------------------------------
                

                目标表 t2:

                   ------------------------------------------------
                   | record_id |  identifier | status |   data1   |
                   ------------------------------------------------
                   |  100      |  Broken     |  11    |   Name1   |
                   |  101      |  Reminder   |  99    |   Name1   |
                   |  102      |  Broken     |  99    |   Name2   |
                   |  103      |  Broken     |  11    |   Name4   |
                   ------------------------------------------------
                

                触发代码:

                create or replace trigger "ca"."t$t1"
                    after update of auth_name1, auth_name2 on ca.t1  
                    for each row
                declare
                    pragma autonomous_transaction;
                begin
                    if :new.auth_name1 is not null and :new.auth_name2 is not null then
                         delete from ca.t2 ml
                         where ml.identifier = 'Broken'
                         and data1 = regexp_substr(:new.auth_name1, 'S+$')||' '||regexp_substr(:new.auth_name1, '^S+')
                         and status = 11;
                         commit;
                    end if;
                end t$t1;
                

                推荐答案

                在父事务回滚时,将自治事务用于除日志记录以外的任何事情几乎肯定是错误的.这不是自治事务的一个很好的用途.

                Using an autonomous transaction for anything other than logging that you want to be preserved when the parent transaction rolls back is almost certainly an error. This is not a good use of an autonomous transaction.

                例如,如果我更新 t1 中的一行,但我的事务回滚,会发生什么情况.t2 更改已经完成并提交,因此它们不会回滚.这通常意味着 t2 数据现在不正确.事务的全部意义在于确保一组更改是原子的,并且要么完全成功,要么完全恢复.允许代码部分成功几乎从来都不是一个好主意.

                What happens, for example, if I update a row in t1 but my transaction rolls back. The t2 changes have already been made and committed so they don't roll back. That generally means that the t2 data is now incorrect. The whole point of transactions is to ensure that a set of changes is atomic and is either completely successful or completely reverted. Allowing code to be partially successful is almost never a good idea.

                我很难看到在这里使用自主交易会给你带来什么.您经常会看到人们错误地使用自主事务来错误地解决突变触发错误.但是您发布的代码不会产生突变触发器错误,除非 t2 上有一个行级触发器也试图更新 t1 或一些类似的机制引入变异表.但是,如果是这种情况,使用自治事务通常会更糟,因为自治事务无法看到父事务中所做的更改,这几乎肯定会导致代码的行为与您期望的不同.

                I'm hard-pressed to see what using an autonomous transaction buys you here. You'll often see people incorrectly using autonomous transactions to incorrectly work around mutating trigger errors. But the code you posted wouldn't generate a mutating trigger error unless there was a row-level trigger on t2 that was also trying to update t1 or some similar mechanism that was introducing a mutating table. If that's the case, though, using an autonomous transaction is generally even worse because the autonomous transaction then cannot see the changes being made in the parent transaction which almost certainly causes the code to behave differently than you would desire.

                这篇关于触发器中的 pragma 自治事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                How to call Oracle function or stored procedure using spring persistence framework?(如何使用 Spring 持久化框架调用 Oracle 函数或存储过程?)
                What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors(什么会导致间歇性 ORA-12519(TNS:找不到合适的处理程序)错误)
                SQL to return the number of working days between 2 passed in dates(SQL 返回两个传入日期之间的工作日数)
                Oracle Date Subtraction(Oracle 日期减法)
                Is using quot;select *quot; for a cursor in PL/SQL considered bad programming?(正在使用“选择 *PL/SQL 中的游标被认为是糟糕的编程?)
                Using sql/plsql, how do you find out which character set a text uses?(使用 sql/plsql,你如何找出文本使用的字符集?)
                  <bdo id='3B78h'></bdo><ul id='3B78h'></ul>
                  <tfoot id='3B78h'></tfoot>
                    <tbody id='3B78h'></tbody>

                  • <small id='3B78h'></small><noframes id='3B78h'>

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