描述性的东西就不来了,搞技术的,最喜欢实在的实例。通过下面的例子,大家很快就能明白insert all 与 insert first 的功能,比文字描述更通俗易懂。

一、INSERT ALL 不带条件用法

SQL> create table t_table1(tid number,tname varchar(100));

Table created

SQL> create table t_table2(tid number,tname varchar(100));

Table created

SQL> insert all into t_table1
  2    (tid, tname)
  3  values
  4    (object_id, object_name) into t_table2
  5    (tid, tname)
  6  values
  7    (object_id, object_name)
  8    select object_id, object_name, object_type
  9      from dba_objects
 10     where wner = 'TEST';

8440 rows inserted

SQL> commit;

Commit complete

SQL> select count(1) from t_table1;

COUNT(1)
----------
      4220

SQL> select count(1) from t_table2;

COUNT(1)
----------
      4220

SQL>

指定所有跟随的多表,都执行无条件的多表插入;

二、INSERT ALL 带条件用法

SQL> create table t_table(tid number,tname varchar(100));

Table created

SQL> create table t_index(iid number,iname varchar(100));

Table created

SQL> create table t_other(oid number,oname varchar(100));

Table created

SQL> insert all when object_type = 'TABLE' then into t_table
  2    (tid, tname)
  3  values
  4    (object_id, object_name) when object_type = 'INDEX' then into t_index
  5    (iid, iname)
  6  values
  7    (object_id, object_name) else into t_other
  8    (oid, oname)
  9  values
 10    (object_id, object_name)
 11    select object_id, object_name, object_type
 12      from dba_objects
 13     where wner = 'TEST';

4220 rows inserted

SQL> commit;

Commit complete

SQL> select count(1) from t_table;

COUNT(1)
----------
      1025

SQL> select count(1) from t_index;

COUNT(1)
----------
      1582

SQL> select count(1) from t_other;

COUNT(1)
----------
      1613

SQL>

Oracle服务器通过相应的WHEN条件过滤,将查询结果分别插入到满足条件的表中;

三、INSERT FIRST 用法

SQL> create table t_table1(tid number,tname varchar(100));

Table created

SQL> create table t_table2(tid number,tname varchar(100));

Table created

SQL> create table t_table3(tid number,tname varchar(100));

Table created

SQL> insert first when object_id < 88554 then into t_table1
  2    (tid, tname)
  3  values
  4    (object_id, object_name) when object_id < 189490 then into t_table2
  5    (tid, tname)
  6  values
  7    (object_id, object_name) else into t_table3
  8    (tid, tname)
  9  values
 10    (object_id, object_name)
 11    select object_id, object_name, object_type
 12      from dba_objects
 13     where wner = 'TEST';

4220 rows inserted

SQL> commit;

Commit complete

SQL> select count(1) from t_table1;

COUNT(1)
----------
       860

SQL> select count(1) from t_table2;

COUNT(1)
----------
      2327

SQL> select count(1) from t_table3;

COUNT(1)
----------
      1033

SQL>

可以看到,用FIRST后,凡是符合第一个条件的就都插入第一个表,其他的数据才在以后的条件里再判断。

Oracle 的 INSERT ALL和INSERT FIRST的更多相关文章

  1. Oracle一个事务中的Insert和Update执行顺序

    今天碰到了一个奇怪的问题,是关于Oracle一个事务中的Insert和Update语句的执行顺序的问题. 首先详细说明下整个过程: 有三张表:A,B,C,Java代码中有一段代码是先在表A中插入一条数 ...

  2. (转)oracle触发器使用:after insert 与before insert的简单使用注意

    本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...

  3. 关于insert /*+ append*/ 各种insert插入速度比较

    来源于:http://www.cnblogs.com/rootq/archive/2009/02/11/1388043.html SQL> select count(*) from t;COUN ...

  4. insert /*+APPEND*/ 各种insert 插入速度比较

    SQL> select count(*) from t;COUNT(*)----------5442048****************************SQL> alter ta ...

  5. INSERT IGNORE 与INSERT INTO的区别

      INSERT IGNORE 与INSERT INTO的区别就是INSERT IGNORE会忽略数据库中已经存在 的数据,如果数据库没有数据,就插入新的数据,如果有数据的话就跳过这条数据.这样就可以 ...

  6. PHP MySQL Insert Into 之 Insert

    向数据库表插入数据 INSERT INTO 语句用于向数据库表添加新记录. 语法 INSERT INTO table_name VALUES (value1, value2,....) 您还可以规定希 ...

  7. INSERT IGNORE 与INSERT INTO的区别,以及replace的用法

    INSERT IGNORE 与INSERT INTO的区别就是INSERT IGNORE会忽略数据库中已经存在 的数据,如果数据库没有数据,就插入新的数据,如果有数据的话就跳过这条数据. 这样就可以保 ...

  8. Hive之insert into与insert overwrite区别

    一.实践先行,直接上手 1. hive 表及数据准备 建表,并插入初始数据.向表中插入 hive> use test; hive> create table kwang_test (id ...

  9. oracle中 SELECT INTO 和INSERT INTO ... SELECT区别

    在Oracle中,将一张表的数据复制到另外一个对象中.通常会有这两种方法:insert into select  和 select into from. 前者可以将select 出来的N行(0到任意数 ...

随机推荐

  1. ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking

    #!/bin/bash # # ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking # 说明: # 本文主要对TI的sdk中 ...

  2. Java [Leetcode 338]Counting Bits

    题目描述: Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculat ...

  3. 01day1

    最大音量 动态规划 题意:给出一个初始值和一个变化序列 c,在第 i 步可以加上或减去 c[i],求 n 步之后能达到的最大值.有一个限定值 maxlevel,在变化过程中值不能超过 maxlevel ...

  4. 【转】Android Studio简单设置

    原文网址:http://ask.android-studio.org/?/article/14 Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以 ...

  5. ASIHttpRequest编译不通过

    转:http://blog.sina.com.cn/s/blog_67a5e47201014tof.html Undefined symbols for architecture i386:   &q ...

  6. 八位彻底改变App Store的iOS开发者

    我们与 app 交互的方式已经被一群聪明的开发者所完全改变,他们的共性是对 app 都有各自独到的见解.下面就是其中最顶尖的八位. Loren Brichter Tweeite 不是 iOS 上第一个 ...

  7. Nginx源码安装及调优配置

    导读 由于Nginx本身的一些优点,轻量,开源,易用,越来越多的公司使用nginx作为自己公司的web应用服务器,本文详细介绍nginx源码安装的同时并对nginx进行优化配置. Nginx编译前的优 ...

  8. java解析XML四种方法

    XML现在已经成为一种通用的数据交换格式,平台的无关性使得很多场合都需要用到XML. XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便 ...

  9. android 官网处理图片 代码

    /** * 获取压缩后的图片 (官网大图片加载对应代码) * * @param res * @param resId * @param reqWidth * 所需图片压缩尺寸最小宽度 * @param ...

  10. NIS Edit&Nsis打包程序发布(安装和卸载)

    转自:http://blog.csdn.net/signjing/article/details/7855855 注意:首选得明确自己需要打包的程序,以及程序需要的dll文件,资源文件等. 1.下载N ...