zoukankan      html  css  js  c++  java
  • 自治事务

    2011年2月21日

    自治事务
    autonomous_transaction
    create table t (msg varchar2(25));
    --自治提交
    create or replace procedure Autonomous_Insert
     as
        pragma autonomous_transaction;
     begin
        insert into t values ('Autonomous Insert');
        commit;
     end;

    --正常的nonautonomous_insert过程
    create or replace procedure NonAutonomous_Insert
     as
     begin
        insert into t values ('NonAutonomous Insert');
        commit;
     end;

    --匿名块中非自治事务的行为
     begin
        insert into t values ('Autonomous Block');
        NonAutonomous_Insert;--调用NonAutonomous_Insert过程
        rollback;
     end;

    select * from t;
    1    Autonomous Block
    2    NonAutonomous Insert
    --匿名块执行的插入由NonAutonomous_Insert过程提交。这两个数据行都已提交,所以rollback命令没有什么可以回滚。把该过程与自治事务过程的行为进行比较

    delete from t;
    commit;

     begin
        insert into t values ('Autonomous Block');
        Autonomous_Insert;--调用Autonomous_Insert过程
        rollback;
     end;

    select * from t;
    1    Autonomous Insert
    /*只有自治事务提交的结果存在t表。匿名块中完成的insert由第四行的回滚语句回滚。自治事务过程的commit对匿名块中开始的父事务没有影响。
    本质上讲,这就抓住了自治事物的精髓。*/
    总结:
       如果在一个“正常”的过程中commit,它不仅会持久保留自己的工作,也会使该会话中为完成的工作成为永久性的。不过,如果在一个自治事务中完成
    commit,只会让这个过程本身的工作成为永久性的。
     
  • 相关阅读:
    *CodeForces 1325E
    CodeForces 1325D
    线性基
    分块
    RabbitMQ学习笔记(四、RabbitMQ队列)
    RabbitMQ学习笔记(三、生产者与消费者)
    RabbitMQ学习笔记(二、RabbitMQ结构)
    RabbitMQ学习笔记(一、消息中间件基础)
    SpringCloud学习笔记(十、SpringCloud Sleuth)
    SpringCloud学习笔记(九、SpringCloud Stream)
  • 原文地址:https://www.cnblogs.com/lanzi/p/1959573.html
Copyright © 2011-2022 走看看