Oracle 复制表

Oracle一个表的数据复制到另一个表
 
一、新表不存在
这种复制方法,只是复制了表结构,表的主键、外键并没有复制。
-- 复制表结果、包含全部数据
create table newtable as select * from oldtable;

-- 复制表结果、不包含任何数据
create table newtable as select * from oldtable where 1=2 ;

-- 复制表结构、包含一部分数据
create table newtable as select * from oldtable where 条件;

-- 复制表结构:指定字段
create table   newtable as select s.c1 ,s.c2 from oldtable s;

-- 复制表结构:指定字段、重命名列名
create table   newtable(id1,name1) as select s.c1,s.c2  from oldtable s;

二、新表存在

1 -- 表结构一样
2 insert into table_name_new select * from table_name_old
3 
4 -- 表结构不一样
5 insert into table_name_new(column1,column2...) select column1,column2... from table_name_old

 

posted @ 2014-10-24 13:50  李国庆liguoqing  阅读(193)  评论(0)    收藏  举报