创建测试表和测试数据

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. Android之TabHost布局(转)

    1.概念 盛放Tab的容器就是TabHost.TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab ...

  2. linux常用命令和选项

    (1)比较两个文件. diff filename1 filename2 -y -W number; -y 并列格式输出 -W 并列格式输出时指定的列宽 (2)linux下抓包 tcpdump有三类关键 ...

  3. Spark Streaming容错的改进和零数据丢失

    本文来自Spark Streaming项目带头人 Tathagata Das的博客文章,他现在就职于Databricks公司.过去曾在UC Berkeley的AMPLab实验室进行大数据和Spark  ...

  4. 【架构】MVP模型

    MVP模型一般要创建三个文件夹:View.Interactor(Model).Presenter 每个部分都有其接口和实现类,就是为了方便回调 这里做一个登陆界面为例子: 接口: Interactor ...

  5. 【jQuery 区别】.click()和$(document).on("click","指定的元素",function(){});的区别

    给出以下的代码展示: //绑定 下一页 的点击事件 $("a[aria-label='Next']").click(function(){ $("a[aria-label ...

  6. [工作中的设计模式]原型模式prototype

    一.模式解析 提起prototype,最近看多了js相关的内容,第一印象首先是js的原型 var Person=function(name){ this.name=name; } Person.pro ...

  7. [BZOJ2599][Race][IOI2011]点分治

    这是为了真正去学一下点分治..然后看了迪克李的ppt 又是一道写(改)了很久的题..终于ac了 1354799 orzliyicheng 2599 Accepted 31936 kb 23584 ms ...

  8. server返回arraylist时,juqery在客户端的处理

    首先,要添加命名控件如下: using System.Web.Services;   server端的方法 [WebMethod()] public static ArrayList GetAuthB ...

  9. java读取utf8配置文件乱码

    email.properties文件如果以ISO-8859-1编码,那么以下的java代码读取中文不会乱码,因为eclipse下中文都被翻译成/u... //in Conf.javaPropertie ...

  10. IOS关于UIViewController之间的切换

    IOS关于UIViewController之间的切换 1.NavigationController切换UIViewController的两种方式 方法一右侧进入 1 SecondViewControl ...