以下演示重启动问题,请注意 before触发器和after触发器的行为区别,因为before触发器会触发两次而导致重启动问题,因此使用after触发器更加高效,应该尽量避免在所有触发器中使用自治事务

-------演示before触发器导致的查询重启动问题

1、创建测试表

create table test4(x number, y number);

insert  into test4 values (1,4);

commit;

2、创建before触发器

create or replace trigger t4
before update on test4 for each row
begin
 dbms_output.put_line('old.y-->'||:old.y);
 dbms_output.put_line('new.y-->'||:new.y);
end;

3、执行更新

session 1:

SQL> select vm.*,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from v$mystat vm where rownum =1;

SID STATISTIC#      VALUE TO_CHAR(SYSDATE,'YYYY-MM-DDHH2

---------- ---------- ---------- ------------------------------

13          0          0 2016-04-28 10:05:44

SQL> update test4 set y=y+1 where x=1;

old.y-->4

new.y-->5

1 row updated

---注:此时不提交

session 2:

SQL> select vm.*,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from v$mystat vm where rownum =1;

SID STATISTIC#      VALUE TO_CHAR(SYSDATE,'YYYY-MM-DDHH2

---------- ---------- ---------- ------------------------------

73          0          0 2016-04-28 10:07:31

SQL> update test4 set y=y+1 where x=1;

---此时session2 会被session阻塞,一直等待session1提交或回滚;

返回至session1,执行提交;

SQL> commit;

Commit complete

---此时切换到session2查看,发现before 触发器打印的信息有点奇怪,这个现象就是重启动

old.y-->4

new.y-->5

old.y-->5

new.y-->6

1 row updated

4、修改before触发器,不使用:old和:new,再次重复上述1~3过程,发现不在出现重启动现象

create or replace trigger t4
before update on test4 for each row
begin
 dbms_output.put_line('this is before trigger');
end;

session1:

SQL> update test4 set y=y+1 where x=1;

this is a before trigger

1 row updated

session2:

SQL> update test4 set y=y+1 where x=1;

this is a before trigger

1 row updated (此时被session1阻塞)

返回session1执行提交:

SQL> commit;

Commit complete

返回session2查看结果:

SQL> update test4 set y=y+1 where x=1;

this is a before trigger

1 row updated

-------演示after触发器不会导致查询重启动

1、先drop before 触发器:

SQL> drop trigger t4;

Trigger dropped

2、创建after触发器:

create or replacetrigger t5

after update on test4 for each row

begin

dbms_output.put_line( 'old.y-->'||:old.y);

dbms_output.put_line('new.y-->'||:new.y);

end;

3、执行更新

session1:

SQL> update test4 set y=y+1 where x=1;

old.y-->7

new.y-->8

1 row updated

session2:

SQL> update test4 set y=y+1 where x=1; ---由于session1未提交,session2此时被阻塞

返回session1,执行提交:

SQL> commit;

Commit complete

返回session2 查看结果:

old.y-->8

new.y-->9

1 row updated

注:此时并没有输出4行,而只是输出2行

----以上信息来自tom书籍

并发与多版本:update重启动问题的更多相关文章

  1. installshield制作的安装包卸载时提示重启动的原因以及解决办法

    原文:installshield制作的安装包卸载时提示重启动的原因以及解决办法 有时候卸载installshield制作的安装包程序,卸载完会提示是否重启电脑以完成所有卸载,产生这个提示的常见原因有如 ...

  2. YARN的重启动问题:RM Restart/RM HA/Timeline Server/NM Restart

    ResourceManger Restart ResourceManager负责资源管理和应用的调度,是YARN的核心组件,有可能存在单点失败的问题.ResourceManager Restart是使 ...

  3. Visual Studio 2013安装Update 3启动crash的解决方法

    Visual Studio 2013安装完Update 3后启动立刻crash,异常信息为: System.InvalidOperationException was unhandled Messag ...

  4. 深入理解java:2.3.2. 并发编程concurrent包 之重入锁/读写锁/条件锁

    重入锁 Java中的重入锁(即ReentrantLock)   与JVM内置锁(即synchronized)一样,是一种排它锁. ReentrantLock提供了多样化的同步,比如有时间限制的同步(定 ...

  5. Hadoop 新生报道(二) hadoop2.6.0 集群系统版本安装和启动配置

    本次基于Hadoop2.6版本进行分布式配置,Linux系统是基于CentOS6.5 64位的版本.在此设置一个主节点和两个从节点. 准备3台虚拟机,分别为: 主机名 IP地址 master 192. ...

  6. centos7版本设置OS启动默认进入图形界面还是文本界面

    相比7之前的版本,在centos7版本中,设置OS启动默认进入图形界面还是文本界面有了点变化 检查当前默认设置 [root@rems2 ~]# systemctl get-default graphi ...

  7. Centos7以上的版本 mysql 无法启动,无法停止问题

    service mysqld start 始终提示如下: Failed to issue method call: Unit mysqld.service failed to load: No suc ...

  8. Java并发编程之线程创建和启动(Thread、Runnable、Callable和Future)

    这一系列的文章暂不涉及Java多线程开发中的底层原理以及JMM.JVM部分的解析(将另文总结),主要关注实际编码中Java并发编程的核心知识点和应知应会部分. 说在前面,Java并发编程的实质,是线程 ...

  9. Java并发(九):重入锁 ReentrantLock

    先做总结: 1.为什么要用ReentrantLock? (1)ReentrantLock与synchronized具有相同的功能和内存语义: (2)synchronized是重量级锁,性能不好.Ree ...

随机推荐

  1. scaleform mobile sdk for android 多点触摸 修正

    修正 scaleform 的多点触控 (随手一记 给后来的人做个参考) scaleform 版本号 4.2.24 (估计这就是最后一个 移动版的版本了,万年没有更新了) 开始 一直以为 scalefo ...

  2. C# 获取word批注信息

    今天在Silverlight 应用程序中实现了 获取word文档批注信息 的功能. 在wcf服务继承接口类中编写的函数如下 /// <summary> /// 获取word批注信息 /// ...

  3. 查看tablespace的使用情况

    by tablespace(使用单位G): SELECT a.tablespace_name,(all_size-b.unuse_size) use_size,b.unuse_size,a.all_s ...

  4. Tsinsen A1516. fx 数位dp

    题目: http://www.tsinsen.com/A1516 A1516. fx 时间限制:2.0s   内存限制:256.0MB    总提交次数:164   AC次数:72   平均分:51. ...

  5. ubuntu14.04安装opencv3.0

    sudo apt-get update sudo apt-get upgrade 搭建C/C++编译环境: sudo apt-get install build-essential 安装关联库: su ...

  6. HW4.10

    public class Solution { public static void main(String[] args) { int count = 0; for(int i = 100; i & ...

  7. HW4.2

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  8. HDU4763 - Theme Section(KMP)

    题目描述 给定一个字符串S,要求你找到一个最长的子串,它既是S的前缀,也是S的后缀,并且在S的内部也出现过(非端点) 题解 CF原题不解释....http://codeforces.com/probl ...

  9. Introduction to SignalR -摘自网络

    What is SignalR? ASP.NET SignalR is a library for ASP.NET developers that simplifies the process of ...

  10. key_t键和ftok函数

    系统建立IPC通讯(如消息队列.共享内存时)必须指定一个ID值.通常情况下,该id值通过ftok函数得到. ftok原型如下: key_t ftok( char * fname, int id ) f ...