创建表,复制内容结构

1. 复制表结构及其数据: create table table_name_new as select * from table_name_old 
2. 只复制表结构: create table table_name_new as select * from table_name_old where 1=2;
 或者: create table table_name_new like table_name_old 
3. 只复制表数据:
如果两个表结构一样:insert into table_name_new select * from table_name_old 
如果两个表结构不一样:insert into table_name_new(column1,column2...) 
                     select column1,column2... from table_name_old
完全COPY另一张表
create table aa as select * from and05
将结果集的数据插入到某表中
insert into and07(cnd215,cnd224,cnd222,cnd225) select z.cnd215,sysdate,
       (select sum(cnd037) from and02 a where a.cnd032='20002901' and a.cnd215=z.cnd215) A,
       (select sum(cnd037) from and02 a where a.cnd032='20002902' and a.cnd215=z.cnd215) B
from and02 z where trunc(cne007,'mm') = trunc(sysdate,'mm') group by cnd215
针对“完全COPY另一张表”的演练
truncate table aa
insert into aa select * from and05;
用另一个表的结果去更新某张表
update and02 a set a.and07id=(select b.and07id from and07 b where a.cnd215=b.cnd215 and trunc(cnd224,'mm')=trunc(sysdate,'mm'));

你可能感兴趣的:(创建表,复制内容结构)