insert/insert all/insert first详解
来源:互联网 发布:影楼美工 编辑:程序博客网 时间:2024/05/22 17:20
insert all官方文档解释:
/*
多表插入语句的限制条件:
1. 只能对表执行多表插入语句,不能对视图或物化视图执行;
2. 不能对远端表执行多表插入语句;
3. 不能使用表集合表达式;
4. 不能超过999个目标列;
5. 在RAC环境中或目标表是索引组织表或目标表上建有BITMAP索引时,多表插入语句不能并行执行;
6. 多表插入语句不支持执行计划稳定性;
7. 多表插入语句中的子查询不能使用序列。
*/
第一步:准备数据
CREATE TABLE t1(product_id NUMBER, product_name VARCHAR2(80),MONTH NUMBER);
INSERT INTO t1 VALUES(111, '苹果',1);
INSERT INTO t1 VALUES(222, '橘子',1);
INSERT INTO t1 VALUES(333, '香蕉',1);
第二部:insert all
INSERT ALL
INTO t2
VALUES (product_id, product_name,MONTH)
INTO t2
VALUES (product_id, product_name,MONTH+1)
INTO t2
VALUES (product_id, product_name,MONTH+2)
INTO t2
VALUES (product_id, product_name,MONTH+3)
SELECT product_id, product_name, MONTH
FROM t1;
这里的表t2的数据下面会用到
---------------------------------------------------------------------------
第三步:有条件的insert all
insert all
when month=1 then
into t3
when month=2 then
into t4
else
into t5
select product_id,product_name,month from t2;
commit;
-------------------------------------------------------------------------
第四部:insert first (需要讲解下)
insert first
when month=1 then
into t3 VALUES(product_id,product_name,month)
when product_id=111 then
into t4 VALUES(product_id,product_name,month)
else
into t5 VALUES(product_id,product_name,month)
select product_id,product_name,month from t2;
commit;
--------------------------------------------------------------------------
根据第二部,t2表的数据做测试。
查询t4表发现:少了一条 111 苹果 1
111 苹果2
111 苹果 3
111 苹果 4
总结:insert first 当数据满足第一when 条件的时候,不会作用在下面的when条件了,
简而言之:当一条数据满足条件后,即使满足后面的条件也不会插入数据库。
正常情况:如果数据满足所有的when条件,每个表都会插入该条数据,insert first
数据只会插入一个表。
完毕
告诉自己你是最棒的!!!!!!
- insert/insert all/insert first详解
- insert all insert first
- INSERT ALL和INSERT FIRST
- insert all与insert first
- INSERT FIRST和INSERT ALL
- insert all/ insert first/ pivoting insert
- INSERT FIRST和INSERT ALL的区别
- INSERT ALL和INSERT FIRST语法
- insert first&insert all的区别
- Oracle 关于INSERT FIRST和INSERT ALL
- INSERT All/ INSERT FIRST 小实验
- INSERT ALL和INSERT FIRST语法
- Oracle Insert first & Insert all 的区别
- oracle:INSERT ALL和INSERT FIRST
- INSERT ALL和INSERT FIRST语法
- insert first&insert all的区别
- oracle:INSERT ALL和INSERT FIRST
- INSERT ALL和INSERT FIRST的区别
- 对Hadoop完全分布式集群下MapReduce日志的提取
- Tomcat运行Web项目,Action中实现资源同步
- JSP
- Redis(Windows)下的开启
- [转载]thinkphp3.2+bootstrap-inputfile多文件上传
- insert/insert all/insert first详解
- 使用babel将es6代码转成es5(二)
- Git GUI中文乱码解决问题
- Unity5.6新功能High-level NavMesh之实时动态烘培NavMesh
- Mysql表类型(即存储引擎)MyISAM和InnoDB区别
- Linux 常见的查找相关笔记
- html中文编码
- C#中如何使用正则表达式
- Idea创建maven的scala项目,没有scala class选项