Oracle把一个表的数据复制到另一个表中

1、新增一个表,通过另一个表的结构和数据:
 
  create table tab2 as select * from tab1;
 
2、如果表存在:
 
  insert into tab2 select * from tab1;
 
3、同一个表中,将A字段的值赋给B字段:
 
  update table_name set B = A;
 
4、将一个表的字段数据插入到另一个表的字段数据中
 
  insert into tab2
      (t_code, t_name)
       select pk_code, pk_name from tab1;
 
  * 如果报提醒:ORA-00928: 缺失 select 关键字错误。
 
  原因是:这里tab1(Field1,Field2,....)不能加单引号
 
5. 第4点的延伸,多个表的多个字段,插入同一个表的多个字段。

  insert into tab1
        (tab_id, tab2_name, tab_code)
         select a.pk_id, b.pk_name, b.pk_code
          from tab1 a, tab2 b
          where a.pk_id = '7777'
          and b.pk_code = '12';

posted on 2019-12-09 14:57  清欢QQ  阅读(16970)  评论(0编辑  收藏  举报