Oracle insert all用法简介
insert all是oracle中用于批量写数据的
现在直接通过例子学习一下,比较简单直观,例子来自《收获,不止SQL优化》一书
环境准备
create table t as select object_name,rownum as object_id
from dba_objects where rownum<=10;
创建两张测试表,不用写数据
create table t1 as select * from t where 1=2;
create table t2 as select * from t where 1=2;
然后演示一下insert all的用法
无条件写数据的情况
insert all into t1
(object_name, object_id) into t2
(object_name, object_id)
select * from t;
commit;
有条件写数据的情况
truncate table t1;
truncate table t2;
insert all when object_id < 5 then into t1
(object_name, object_id) when object_id >= 5 then into t2
(object_name, object_id)
select * from t;
commit;
insert first
insert first情况,介绍一下insert first的用法,insert first用法和insert all类似,区别的是insert first多了筛选的步骤,简单来说就是和insert all一样,符合条件的同样会写数据,不过已经存在数据了,insert first是不会写入的,而insert all是会出现重复数据的情况
truncate table t1;
truncate table t2;
insert first when object_id = 1 then into t1
(object_name, object_id) when object_id <= 5 then into t2
(object_name, object_id)
select * from t;
commit;
pivoting insert
然后再演示一下pivoting insert的情况,pivoting insert可以说是insert all的一直特殊情况,不过oracle官方还是区分出来,pivoting insert可以翻译为旋转写入,名称的不重要,看一下例子就懂了
环境准备
drop table sales_source_data;
create table sales_source_data(
employee_id number(10),
week_id number(2),
sales_mon number(8,2),
sales_tue number(8,2),
sales_wed number(8,2),
sales_thur number(8,2),
sales_fri number(8,2)
);
insert into sales_source_data values(280,6,2000,3000,4000,5000,6000);
commit;
create table sales_info(
employee_id number(10),
week number(2),
sales number(8,2)
);
按照条件进行写数据
insert all
into sales_info values(employee_id,week_id,sales_mon)
into sales_info values(employee_id,week_id,sales_tue)
into sales_info values(employee_id,week_id,sales_wed)
into sales_info values(employee_id,week_id,sales_thur)
into sales_info values(employee_id,week_id,sales_fri)
select employee_id,week_id,sales_mon,sales_tue,
sales_wed,sales_thur,sales_fri
from sales_source_data;
commit;
Oracle insert all用法简介的更多相关文章
- ORACLE INSERT ALL 用法
1INSERT ALL 1.1句法 multi_table_insert :: = conditional_insert_clause :: = 1.2multi_table_insert 在多表插入 ...
- Oracle笔记-Multitable INSERT 的用法
[转自] http://blog.chinaunix.net/uid-8504518-id-3310531.html 为避免日趋衰退的记忆力,参考官方E文文档<Introduction to ...
- [转]ORACLE的ProC用法讲解
pro*c是高级的用法,OCI是oracle的基础用法 如何编译.pc文件: proc code=cpp parse=none iname=filename.pc oname=filename.cp ...
- 【转】关于oracle with as用法
原文链接:关于oracle with as用法 with as语法–针对一个别名with tmp as (select * from tb_name) –针对多个别名with tmp as (se ...
- Apache自带压力测试工具ab用法简介
ab命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx.lighthttp ...
- MSSQL Sql加密函数 hashbytes 用法简介
转自:http://www.maomao365.com/?p=4732 一.mssql sql hashbytes 函数简介 hashbytes函数功能为:返回一个字符,通过 MD2.MD4.MD5. ...
- MySQL基础之STRAIGHT JOIN用法简介
MySQL基础之STRAIGHT JOIN用法简介 引用mysql官方手册的说法: STRAIGHT_JOIN is similar to JOIN, except that the left tab ...
- MySQL变量介绍和用法简介
目录 一.用户变量 1.1.用户变量定义 1.2.用户变量用法 二.系统变量 2.1 系统变量简单介绍 2.2 系统变量用法简介 本博客介绍一下MySQL中变量的用法和注意细节 @ 一.用户变量 1. ...
- ORACLE 中ROWNUM用法总结(转)
ORACLE 中ROWNUM用法总结! 对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between...and,只能用以上符号(<.<=.!=) ...
随机推荐
- Leetcode 169 Majority Element 分治
在一个长度为n的数组中找出出现次数超过(n+1)/2次的数 说明请参考编程之美中的2.3 class Solution { public: int majorityElement(vector< ...
- 深入WPF中的图像画刷(ImageBrush)之2——ImageBrush的铺设方式
原文:深入WPF中的图像画刷(ImageBrush)之2--ImageBrush的铺设方式 ------------------------------------------------------ ...
- HDU 5073 Galaxy(Anshan 2014)(数学推导,贪婪)
Galaxy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total S ...
- WPF 将Bitmapsource转换到Emgu.cv.image
原文:WPF 将Bitmapsource转换到Emgu.cv.image Transform WPF BitmapSource to Emgu.CV.Image******* /// <summ ...
- Hadoop MapReduce编程入门案例
Hadoop入门例程简介 一个.有些指令 (1)Hadoop新与旧API差异 新API倾向于使用虚拟课堂(象类),而不是接口.由于这更easy扩展. 比如,能够无需改动类的实现而在虚类中加入一个方法( ...
- vs2015 生成 cordova 页面中文乱码
原文:vs2015 生成 cordova 页面中文乱码 1.用VS2015新创建Cordova项目,启动运行index.html 中文显示乱码 解决方案: 1.使用text/html通用解析编码utf ...
- BGP的一网双平面规划
网络拓扑: XRV1 ===================================================================== # sysname XRV1# boa ...
- Win8Metro(C#)数字图像处理--2.18图像平移变换
原文:Win8Metro(C#)数字图像处理--2.18图像平移变换 [函数名称] 图像平移变换函数TranslationProcess(WriteableBitmap src,int x,in ...
- win10 uwp 异步转同步
原文:win10 uwp 异步转同步 有很多方法都是异步,那么如何从异步转到同步? 可以使用的方法需要获得是否有返回值,返回值是否需要. 如果需要返回值,使用GetResults 如从文件夹获取文件: ...
- 零元学Expression Blend 4 - Chapter 28 ListBox的基本运用与更改预设样式
原文:零元学Expression Blend 4 - Chapter 28 ListBox的基本运用与更改预设样式 本章将先教大家认识ListBox的基本运用与更改预设样式 本章将先教大家认识List ...