--1.无条件的多表insert all
create table emp_1 as select id,last_name from s_emp where 1=0;
create table emp_2 as select * from s_emp where 1=0;
create table emp_3 as select * from s_emp where 1=0;
--没有条件,向多个目标表全量插入,必须有all
insert all
--不指定emp_1后面的列,也不指定values,那么emp_1中的所有列类型和顺序与查询的列的类型和顺序一致
--也就是emp_1中只有查询结果中的那几列,而且类型和顺序与其一致
into emp_1
--指定了emp_2后面的列,没有values,表示emp_2中要插入的列被选择出来,与查询的结果列类型和顺序一致
--emp_2中也可能有很多列,不止这两列
into emp_2(id,last_name)
--指定emp_3后面的列,也指定values,那么values后面的列名必须与查询结果一致,如果
--查询中有别名,必须在values中使用别名。emp_3中指定的列类型和顺序必须与values保持一致
--emp_3中也可能列数大于指定的列数
into emp_3(id,last_name) values(s_id,s_last_name)
select id s_id,last_name s_last_name
from s_emp; --2.带条件的多表insert all
--conditional insert all:all可以省略,但不建议.
insert all
--将查询结果中为s_id>20的插入,条件中指定的列必须与查询的结果名字一致,如果有别名,用别名
when s_id>20 then
into emp_1
--s_last_name为M开头的插入,可能插入的行与s_id>20有重复
when s_last_name like 'M%'then
into emp_2(id,last_name)
--如果指定else,则不满足上面两个条件的插入到emp_3,插入的行不会与上面两个重复
else
into emp_3(id,last_name) values(s_id,s_last_name)
select id s_id,last_name s_last_name
from s_emp; --3.带条件的多表insert first
--Insert first只有带条件的,没有不带条件的。
--语法只要将insert all中的all改为first就可以了。这里的first不可以省略。省略那么默认就是all
insert first
--将查询结果中为s_id>20的插入,条件中指定的列必须与查询的结果名字一致,如果有别名,用别名
when s_id>20 then
into emp_1
--s_last_name为M开头的插入,插入的行与s_id>20没有重复
when s_last_name like 'M%'then
into emp_2(id,last_name)
--如果指定else,则不满足上面两个条件的插入到emp_3,插入的行不会与上面两个重复
else
into emp_3(id,last_name) values(s_id,s_last_name)
select id s_id,last_name s_last_name
from s_emp; --4.选择插入Pivoting insert
--使用pivoting insert实现将非关系性表记录转换为关系型表中存储。Pivot旋转是OLAP中的一个基本改变,提供多维度数据分析。
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; 多表insert使用限制:
1. 只能对table使用多表insert,不能对视图或物化视图使用。
2. 不能对远程表进行这个插入操作。
3. 在做多表insert操作,不能指定一个表的集合表达式。
4. 多表insert中的的into目标表加在一起的列数不能超过999 个。

多表insert操作详解的更多相关文章

  1. MyBatis魔法堂:Insert操作详解(返回主键、批量插入)

    一.前言    数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解   其属性如下: parameterType  ...

  2. MyBatis魔法堂:Insert操作详解

    一.前言 数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解 其属性如下: parameterType:入参的全限 ...

  3. MyBatis的Insert操作详解

    一.前言 数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解 其属性如下: parameterType ,入参的全 ...

  4. 问题:oracle select into;结果:oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解

    oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解 (2011-07-08 08:59:47) 转载▼ 标签: it 分类: oracle 我们经常会遇 ...

  5. [Android新手区] SQLite 操作详解--SQL语法

    该文章完全摘自转自:北大青鸟[Android新手区] SQLite 操作详解--SQL语法  :http://home.bdqn.cn/thread-49363-1-1.html SQLite库可以解 ...

  6. MySQL 操作详解

    MySQL 操作详解 一.实验简介 本节实验中学习并实践 MySQL 上创建数据库.创建表.查找信息等详细的语法及参数使用方法. 二.创建并使用数据库 1. 创建并选择数据库 使用SHOW语句找出服务 ...

  7. Skip List(跳跃表)原理详解与实现【转】

    转自:http://dsqiu.iteye.com/blog/1705530 Skip List(跳跃表)原理详解与实现 本文内容框架: §1 Skip List 介绍 §2 Skip List 定义 ...

  8. Python对Excel操作详解

      Python对Excel操作详解 文档摘要: 本文档主要介绍如何通过python对office excel进行读写操作,使用了xlrd.xlwt和xlutils模块.另外还演示了如何通过Tcl   ...

  9. python/ORM操作详解

    一.python/ORM操作详解 ===================增==================== models.UserInfo.objects.create(title='alex ...

随机推荐

  1. PHP环境配置(1)

    Apache下载 Apache下载地址:http://httpd.apache.org/download.cgi 第一步:点击Files for Microsoft Windows 第二步:点击Apa ...

  2. libevent源码阅读笔记(一):libevent对epoll的封装

    title: libevent源码阅读笔记(一):libevent对epoll的封装 最近开始阅读网络库libevent的源码,阅读源码之前,大致看了张亮写的几篇博文(libevent源码深度剖析 h ...

  3. [LeetCode] Find K Closest Elements 寻找K个最近元素

    Given a sorted array, two integers k and x, find the k closest elements to x in the array. The resul ...

  4. [LeetCode] Most Frequent Subtree Sum 出现频率最高的子树和

    Given the root of a tree, you are asked to find the most frequent subtree sum. The subtree sum of a ...

  5. C++Primer学习——const

    Const int size = 512; 在编译的时候,编译器会把用到该变量的地方全部替换成对应的值. const&可以绑定字面值,所以当用常量引用绑定一个常量时,是否可以看成那个值在编译阶 ...

  6. 【USACO Feb 2014】Cow Decathlon

    题目描述 约翰有 N 头奶牛,组成了一直队伍参加全能比赛.比赛一共有 N 项,每头奶牛必须参加一项比 赛,每项比赛也必须有一头奶牛参加.任何一头奶牛可以胜任任何一项比赛,但得分不一样.如果第 i 头奶 ...

  7. 2015 多校联赛 ——HDU5350(huffman)

    Problem Description MZL is a mysterious mathematician, and he proposed a mysterious function at his ...

  8. 【Codeforces AIM Tech Round 4 (Div. 2) C】

    ·将排序限制于子序列中,又可以说明什么呢? C. Sorting by Subsequences ·英文题,述大意:       输入一个长度为n的无重复元素的序列{a1,a2……an}(1<= ...

  9. bzoj2669[cqoi2012]局部极小值 容斥+状压dp

    2669: [cqoi2012]局部极小值 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 774  Solved: 411[Submit][Status ...

  10. Windows下免安装版mysql5.7的初始密码

    MySQL5.7之后,初始密码不在默认为空,而是随机生成的密码. 在mysql/data目录下,生成了一个.err文件(等同linux下的log日志文件,此文件会被mysql服务占用). 使用记事本可 ...