创建测试表和测试数据

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中设定EditText的输入长度(转)

    如何限定Android的Text中的输入长度呢? 方法一:可以在layout xml中加上属性android:maxLength 比如: <EditText         android:id ...

  2. markdown使用总结

    # markdown简介> Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的HTML页面. —— [维基百科]( https://zh.w ...

  3. 基于XMPP协议的Android即时通信系

    以前做过一个基于XMPP协议的聊天社交软件,总结了一下.发出来. 设计基于开源的XMPP即时通信协议,采用C/S体系结构,通过GPRS无线网络用TCP协议连接到服务器,以架设开源的Openfn'e服务 ...

  4. Loadrunner中参数化实战(8)-Unique+Each occurrence

    参数化数据30条: 脚本如下,演示登录,投资,退出操作是,打印手机号: 首先验证Vugen中迭代: Unique+Each occurrence 设置迭代4次Action 结果如下:

  5. DLL中传递STL参数(如Vector或者list等)会遇到的问题[转载]

    最近的一个项目中遇到了调用别人的sdk接口(dll库)而传给我的是一个vector指针,用完之后还要我来删除的情况.这个过程中首先就是在我的exe中将其vector指针转为相应指针再获取vector中 ...

  6. vim 清空

    插入模式 首先执行gg 跳至文件首行 然后执行dG就清空了整个文件 还有一种方法就要退出VIM,然后使用echo > file ,这样也能快速清空文件内容

  7. css/js(工作中遇到的问题)

    移动设备点击时去掉外加的蓝色边框 a, input, button { -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit-tap-highligh ...

  8. Codeforces 682C Alyona and the Tree(树形DP)

    题目大概说给一棵点有权.边也有权的树.一个结点v不高兴当且仅当存在一个其子树上的结点u,使得v到u路径上的边权和大于u的权值.现在要不断地删除叶子结点使得所有结点都高兴,问最少删几个叶子结点. 一开始 ...

  9. CF460 A. Vasya and Socks

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  10. Modify a Stored Procedure using SQL Server Management Studio

    In Object Explorer, connect to an instance of Database Engine and then expand that instance. Expand  ...