• oracle 事务


    设置保存点
    savepoint test;
    取消部分事务
    rollback to test;
    取消全部事务
    rollback;

    insert into emp(empno, job) values(1, '测试');
    insert into emp(empno, job) values(2, '测试2');
    insert into emp(empno, job) values(3, '测试3');
    commit;
    savepoint test1;
    delete emp where empno = 1;
    savepoint test2;
    delete emp where empno = 2;
    savepoint test3;
    delete emp where empno = 3;
    rollback to test3;
    rollback to test2;
    rollback to test1;

    delete emp where empno in(1, 2, 3);
    insert into emp(empno, job) values(1, '测试');
    insert into emp(empno, job) values(2, '测试2');
    insert into emp(empno, job) values(3, '测试3');
    commit;
    savepoint test1;
    delete emp where empno = 1;
    savepoint test2;
    delete emp where empno = 2;
    savepoint test3;
    delete emp where empno = 3;
    rollback to test1;
    rollback to test2; //报错,保存点不存在
    rollback to test3; //报错,保存点不存在

    delete emp where empno in(1, 2, 3);
    insert into emp(empno, job) values(1, '测试');
    insert into emp(empno, job) values(2, '测试2');
    insert into emp(empno, job) values(3, '测试3');
    commit;
    savepoint test1;
    delete emp where empno = 1;
    savepoint test2;
    delete emp where empno = 2;
    savepoint test3;
    delete emp where empno = 3;
    rollback; // 已回退到test1
    rollback to test1; //报错,保存点不存在
    rollback to test2; //报错,保存点不存在
    rollback to test3; //报错,保存点不存在


     java 事务

    1、connection.setAutoCommit(false);
    Statement statement = connection.createStatement();
    statement.executeUpdate("update ...");
    int i = 7/0;
    statement.executeUpdate("update ...");
    2、connection.commit();
    异常处理:
    3、connection.rollback();


    只读事务

    使用只读事务可以确保用户只能取得某个时间点的数据。假定机票代售点每天18点开始统计今天的销售情况,这时可以使用只读事务,尽管这时其它会话可能会提交新的事务,但是只读事务将不会取得最新变化的数据。
    设置只读事务
    set transaction read only;

    开启一个sqlplus
    conn system/root ; // 注意不要使用sysdba登陆,否则不起作用
    set transaction read only;
    select * from emp; 14条记录

    再开启一个sqlplus
    conn scott/root;
    select * from emp; 14条记录
    insert into emp(empno, ename) values(1, '张三');
    commit;
    select * from emp; 15条记录

    system用户:
    select * from emp; 15条记录

  • 相关阅读:
    春节不回家
    夜间突然发烧,无法入眠
    歌词写得真好
    近日看到网上许多BBS寻找SAP及ABAP程序的学习资料,本人深知学习的艰辛与不易,特贡献自己多年的学习资料,完全免费
    人生的真谛
    SMARTFORMS的调用方法(作者:曹玉平)
    自己给自己当医生
    将ocx添加到.NET
    AQtime + ocx/dll
    ActiveX:创建安装:
  • 原文地址:https://www.cnblogs.com/Mike_Chang/p/9291238.html
Copyright © 2020-2023  润新知