您的位置:首页 > 数据库 > Oracle

Oracle数据复制

2016-12-20 15:29 302 查看
总结一下数据库中复制表的各种方式

复制表

1.仅复制表的字段,不复制表内容

create table New_TabelName as (select * from Older_TableName where 1<0 )


2.已经存在New_TabelName表,且Older_TableName与New_TabelName表结构相同,将Older_TableName中的所有满足条件的记录复制New_TabelName中:

insert into New_TabelName select * from Older_TableName where Condition1 and Condition2...


3.不管Older_TableName和New_TabelName表结构是否相同,将Older_TableName中指定的字段Atrr1,Attr2,Attr3复制到New_TabelName的Attr_a,Attr_b,Attr_c:

insert into New_TabelName(Attr_a,Attr_b,Attr_c) select Atrr1,Attr2,Attr3 from Older_TableName where Condition1 and Condition2...


4.如果New_TableName不存在,将旧表Older_TableName中的字段以及相应的数值全部复制到New_TableName中:

Method1

create table … as…

create table New_TabelName as (select * from Older_TableName )


Method2

select … into ta**重点内容**ble2 from table1

select Attr1,Attr2,Attr3 into New_TabelName from Older_TableName where Condition1 and Condition2...


select into from跟insert into select from两种表复制语句区别详细见http://www.myexception.cn/database/479886.html

但Method2方法在SQL/PL中运行报错:ORA-00905: 缺少关键字,具体原因进一步查找中

5.New_TableName不存在,将旧表Older_TableName中指定字段以及满足条件的表内容复制到New_TableName中:

create table New_TabelName as (select Attr1,Attr2,Attr3 from Older_TableName t
where  t.Attr1 is not null and t.Attr2>111)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: