创建测试表和测试数据

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中复制表和数据 && 多表插入语句的更多相关文章

  1. 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 阅读 ...

  2. 快速将一个表的数据生成SQL插入语句

    将一个表中的数据生成SQL插入语句,方便系统快速初始化,在数据库中执行创建以下过程就可以了. ) Drop Procedure GenerateData go CREATE PROCEDURE Gen ...

  3. 【Oracle】往Oracle11g的某表插入近千万条记录,耗时略超一小时

    和MySql的对比下,两者有数量级的差距. 表ddl: CREATE TABLE tb04 ( "ID" ,) not null primary key, "NAME&q ...

  4. 【Oracle】删除(释放)数据文件/表空间流程

    oracle删除(释放)数据文件/表空间流程 生产环境:数据库里空间不足,niptest 表空间251G,只使用了17G 再alter database datafile '...../niptest ...

  5. mysql生成20万条数据(连表插入)

    创建一个存储过程 DELIMITER $$ -- 设置定界符为$$,与';'意思相同,防止相同符号产生冲突 USE `yunkc_base1`$$ -- 使用数据库 DROP PROCEDURE IF ...

  6. 如何在Oracle中复制表结构和表数据

    1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...

  7. Oracle中复制表结构和表数据

    一.复制表结构及其数据 create table new_table as (select * from old_table); 二.只复制表结构 create table new_table as ...

  8. 如何在Oracle中复制表结构和表数据 【转载】

    1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...

  9. 【转载】如何在Oracle中复制表结构和表数据

    1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 2. 只复制表结构: create table ta ...

随机推荐

  1. 背景虚化 Google Camera App Nokia Refocus HTC One M8 的 Duo景深相机

    背景虚化是单反中一种比较常见的拍照形式,参看 http://www.techbang.com/posts/%2017842 https://refocus.nokia.com/

  2. 【java基础】重载与重写

    前言 : 很早的时候,我就知道这两个东西,但是,也仅仅是停留在知道的程度而已,对于什么是重写,什么事重载,还是感到十分的迷惑,迷茫.正好,在软考复习时又经历这两个东西,细心一点,探究了一下,有点收获, ...

  3. How to AC it

    旋转卡壳 DP,网络流

  4. AchartEngine的柱状图属性设置

    1.      修改背景色或设置背景图片 背景色设置需要设置两项:setMarginsColor(设置四边颜色)以及setBackgroundColor(设置中间背景色) 设置背景图片:        ...

  5. 《DSP using MATLAB》示例Example4.4

    代码: x1 = [2, 3, 4]; x2 = [3, 4, 5, 6]; % x1 x2 sequences % n1 = 0:1:2; n2 = 0:1:3; n1 = 0:1:length(x ...

  6. DSP using MATLAB示例Example3.16

    代码: b = [0.0181, 0.0543, 0.0543, 0.0181]; % filter coefficient array b a = [1.0000, -1.7600, 1.1829, ...

  7. 用Python做自然语言处理必知的八个工具【转载】

    Python以其清晰简洁的语法.易用和可扩展性以及丰富庞大的库深受广大开发者喜爱.其内置的非常强大的机器学习代码库和数学库,使Python理所当然成为自然语言处理的开发利器. 那么使用Python进行 ...

  8. git merge 与 rebase 的区别

    http://gitbook.liuhui998.com/4_2.html merge rebase

  9. Jenkins基础 - 常用配置操作

    1.修改jenkins的根目录,默认地在C:\Users\用户名\.jenkins下(win7) 或C:\Documents and Settings\用户名\.jenkins(xp) 修改步骤: 增 ...

  10. BZOJ 1029 & 丝帛贪心

    题意: 小刚在玩JSOI提供的一个称之为“建筑抢修”的电脑游戏:经过了一场激烈的战斗,T部落消灭了所有z部落的入侵者.但是T部落的基地里已经有N个建筑设 施受到了严重的损伤,如果不尽快修复的话,这些建 ...