oracle中复制表和数据 && 多表插入语句
创建测试表和测试数据
create table test (id number,name varchar(10));
insert into test values(1,'liufang');
insert into test values(2,'xiaozhang');
insert into test values(3,'dawei');
insert into test values(4,'laotan');
insert into test values(5,'laotan');
insert into test values(6,'laotan');
insert into test values(7,'dawei');
1、复制表和表中的数据,我们可以通过下面的语句来实现
(注:复制表不包含默认值和约束等信息,使用下面方法复制表和数据后需要重新见默认值及索引、约束信息等)
create table test2 as select * from test;
也可以待条件去复制
create table test3 as select * from test where name='laotan'
还可以先去定义表,然后再添加数据
create table test2 as select * from test where 2=1;
insert into test2 select * from test;
2、多表插入语句
先指定复制两个测试表(指定列复制)
create table emp1 as select sequen,ename,sal from emp where 1=2;
create table emp2 as select sequen,ename,cid from emp where 1=2;
下面我们使用四种多表插入语句
a、 insert all 无条件插入
insert all
into emp1(sequen,ename,sal) values (sequen,ename,sal)
into emp2(sequen,ename,cid) values (sequen,ename,cid)
select sequen,ename,sal,cid from emp ;
insert all 有条件插入:上面是没有加条件的,同时向表中插入数据,而且两个表的数据条数也一致,下面是加上不同的条件插入
insert all
when sal>=2000 then
into emp1(sequen,ename,sal) values (sequen,ename,sal)
when cid in(1,2) then
into emp2(sequen,ename,cid) values (sequen,ename,cid)
select sequen,ename,sal,cid from emp ;
b、insert first插入(前面根据条件插入后是有相同的数据插入的,如果不想两个表中数据有重复相同的可以使用insert first)
insert first
when sal>=2000 then
into emp1(sequen,ename,sal) values (sequen,ename,sal)
when cid in(1,2) then
into emp2(sequen,ename,cid) values (sequen,ename,cid)
select sequen,ename,sal,cid from emp ;
insert first 语句中,当地一个表符合条件后,的二个表就不在插入对饮的行,表emp1中不会出现和表emp2相同的数据
这就是两种插入方式的不同之处
oracle中复制表和数据 && 多表插入语句的更多相关文章
- Oracle中复制表的方法(create as select、insert into select、select into)
转: Oracle中复制表的方法(create as select.insert into select.select into) 2018-07-30 22:10:37 小白白白又白cdllp 阅读 ...
- 快速将一个表的数据生成SQL插入语句
将一个表中的数据生成SQL插入语句,方便系统快速初始化,在数据库中执行创建以下过程就可以了. ) Drop Procedure GenerateData go CREATE PROCEDURE Gen ...
- 【Oracle】往Oracle11g的某表插入近千万条记录,耗时略超一小时
和MySql的对比下,两者有数量级的差距. 表ddl: CREATE TABLE tb04 ( "ID" ,) not null primary key, "NAME&q ...
- 【Oracle】删除(释放)数据文件/表空间流程
oracle删除(释放)数据文件/表空间流程 生产环境:数据库里空间不足,niptest 表空间251G,只使用了17G 再alter database datafile '...../niptest ...
- mysql生成20万条数据(连表插入)
创建一个存储过程 DELIMITER $$ -- 设置定界符为$$,与';'意思相同,防止相同符号产生冲突 USE `yunkc_base1`$$ -- 使用数据库 DROP PROCEDURE IF ...
- 如何在Oracle中复制表结构和表数据
1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...
- Oracle中复制表结构和表数据
一.复制表结构及其数据 create table new_table as (select * from old_table); 二.只复制表结构 create table new_table as ...
- 如何在Oracle中复制表结构和表数据 【转载】
1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...
- 【转载】如何在Oracle中复制表结构和表数据
1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...
随机推荐
- Convert Object to XML using LINQ
Convert Object to XML using LINQ. Also the object contains other object list. Following is the Class ...
- Java学习笔记(七)——对象
一.类与对象 1.类的定义 类就是模型,确定对象将会拥有的特征(属性)和行为(方法). 2.类的特点 (1)类是对象的类型 (2)具有相同属性和方法的一组对象的集合. 3.对象的属性: 对象具有的各种 ...
- PowerDesigner 16.5
PowerDesigner165_破解文件.rar 链接:http://pan.baidu.com/s/1hqEDUCG 636KB PowerDesigner165_Evaluation ...
- MySQL数据库监控
MySQL MTOP由PHP和Python开发,所以监控机需要安装PHP运行环境和Python环境.需要的核心包如下: 1.MySQL 5.0及以上(用来存储监控系统采集的数据) 2.Apache 2 ...
- MySQL常用数据类型小结
在 MySQL 中,有三种主要的类型:字符串.数字和日期/时间类型. 目录 [隐藏] 1 字符串类型 2 数值类型 3 日期和时间类型 4 使用建议 5 艺搜参考 字符串类型 CHAR 0-255字 ...
- (转)qsort和sort
1.qsort函数: 原 型: void qsort(void *base, int nelem, int width, int (*fcmp)(const void *,const void *)) ...
- ubuntu 下python版本切换
1. 安装ubuuntu 14.04之后python的默认版本为2.7.6但是我想使用python的版本为3.4 可以打开终端:输入:alias python = python3
- [工作bug]一个weblogic跨应用导致session丢失的bug之旅
近来,发布一个应用,开发和本地测试一切都好,一旦部署到测试环境之后,坑爹的问题随之而来,应用程序不定时的超时,导致用户正在操作过程中被踢了出来,纠结了几天,终于在今天将此问题搞定: 1.系统架构 系统 ...
- Lost Cows
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9669 Accepted: 6228 Description N (2 ...
- 如何用distinct消除重复记录的同时又能选取多个字段值?
http://www.cnblogs.com/warioland/archive/2012/05/30/2526128.html