Oracle 的 INSERT ALL和INSERT FIRST
描述性的东西就不来了,搞技术的,最喜欢实在的实例。通过下面的例子,大家很快就能明白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的更多相关文章
- Oracle一个事务中的Insert和Update执行顺序
今天碰到了一个奇怪的问题,是关于Oracle一个事务中的Insert和Update语句的执行顺序的问题. 首先详细说明下整个过程: 有三张表:A,B,C,Java代码中有一段代码是先在表A中插入一条数 ...
- (转)oracle触发器使用:after insert 与before insert的简单使用注意
本文转载自:http://blog.csdn.net/kuangfengbuyi/article/details/41446125 创建触发器时,触发器类型为after insert , 在begin ...
- 关于insert /*+ append*/ 各种insert插入速度比较
来源于:http://www.cnblogs.com/rootq/archive/2009/02/11/1388043.html SQL> select count(*) from t;COUN ...
- insert /*+APPEND*/ 各种insert 插入速度比较
SQL> select count(*) from t;COUNT(*)----------5442048****************************SQL> alter ta ...
- INSERT IGNORE 与INSERT INTO的区别
INSERT IGNORE 与INSERT INTO的区别就是INSERT IGNORE会忽略数据库中已经存在 的数据,如果数据库没有数据,就插入新的数据,如果有数据的话就跳过这条数据.这样就可以 ...
- PHP MySQL Insert Into 之 Insert
向数据库表插入数据 INSERT INTO 语句用于向数据库表添加新记录. 语法 INSERT INTO table_name VALUES (value1, value2,....) 您还可以规定希 ...
- INSERT IGNORE 与INSERT INTO的区别,以及replace的用法
INSERT IGNORE 与INSERT INTO的区别就是INSERT IGNORE会忽略数据库中已经存在 的数据,如果数据库没有数据,就插入新的数据,如果有数据的话就跳过这条数据. 这样就可以保 ...
- Hive之insert into与insert overwrite区别
一.实践先行,直接上手 1. hive 表及数据准备 建表,并插入初始数据.向表中插入 hive> use test; hive> create table kwang_test (id ...
- oracle中 SELECT INTO 和INSERT INTO ... SELECT区别
在Oracle中,将一张表的数据复制到另外一个对象中.通常会有这两种方法:insert into select 和 select into from. 前者可以将select 出来的N行(0到任意数 ...
随机推荐
- I.MX6 Goodix GT9xx touchscreen driver porting
/************************************************************************ * I.MX6 Goodix GT9xx touch ...
- LeetCode Best Time to Buy and Sell Stock 买卖股票的最佳时机 (DP)
题意:给定一个序列,第i个元素代表第i天这支股票的价格,问在最佳时机买入和卖出能赚多少钱?只买一次,且仅1股,假设本钱无限. 思路:要找一个最低价的时候买入,在最高价的时候卖出利润会最大.但是时间是不 ...
- NPAIRS框架的理解
<The NPAIRS Computational Statistics Framework for Data Analysis in Neuroimaging> Strother. pe ...
- 分享一段H264视频和AAC音频的RTP封包代码
1. H264视频的RTP封包 static int h264_parse(Track *tr, uint8_t *data, size_t len) { h264_priv *priv = tr-& ...
- cimge 这次能够图片大小尺寸
CImage imSrc,imDest;imSrc.Load(……);//读入原始图片imDest.Create(……)//创建新大小的图片imSrc.StretchBlt(imDest.GetDC( ...
- wap版和pc版的旋转js
<script type="text/javascript"> var evt = "onorientationchange" in window ...
- Delphi 自带的那个 Hand 光标很难看?没关系,一行代码解决问题:
Delphi 自带的那个 Hand 光标很难看?没关系,一行代码解决问题: Screen.Cursors[crHandPoint] := LoadCursor(0, IDC_HAND);放在主窗体 O ...
- VelocityTracker简单用法
VelocityTracker顾名思义即速度跟踪,在android中主要应用于touch event, VelocityTracker通过跟踪一连串事件实时计算出 当前的速度,这样的用法在androi ...
- UIImage 缩放等效果处理
//等比率缩放 - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{ // 创建一个bitmap的context // 并把它设置成为当 ...
- [Irving] SQL 2005/SQL 2008 备份数据库并自动删除N天前备份的脚本
以下为SQL脚本,本人以执行计划来调用,所以改成了执行命令,大家可根据自己需要改为存储过程使用 )='E:\MsBackUp\SqlAutoBackup\' --备份路径; --备份类型为全备,1为差 ...