打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
oracle根据已有表及数据创建表分区并导入数据
oracle根据已有表及数据创建表分区并导入数据
 
假设情景: 
现有System.Test表,数据量过千万,处于ts_Test表空间中。 
表中有列A,将A=6与A小于6的数据进行分区 
  www.2cto.com  
确保不会有外部程序修改需要建表分区的表 
 
1. 对需要重建表分区的表进行备份,导出dmp,防止数据丢失 
Sql代码  
exp 用户名/密码@tns名 file=c:/test.dmp log=c:/test.log full=n rows=y buffer=10240000 tables=System.Test  
 
2. 创建临时表,用来回导数据 
Sql代码  
create table system.Test_Bak  
tablespace ts_Test  
as  
select * from System.Test;  
 
3. 校验数据行数   www.2cto.com  
Sql代码  
select count('x') c1 from System.Test;  
select count('x') c2 from System.Test_Bak;  
 
如果行数不一致需查找原因 
 
4. 重建表 
 
Sql代码  
truncate table System.Test;  
drop table System.Test;  
 
 
Sql代码  
create table System.Test  
tablespace ts_Test  
PARTITION BY RANGE(A)  
(  
  PARTITION P1 VALUES LESS THAN ('6')  
      TABLESPACE TS_TEST  
   ,  
  PARTITION P2 VALUES LESS THAN ('7')  
      TABLESPACE TS_TEST,  
  PARTITION P3 VALUES LESS THAN (MAXVALUE)  
      TABLESPACE TS_TEST  
)  
as  
select   
  from System.Test_Bak;  
 
   第4步执行完之后,表里的数据就分散到了P1和P2分区中 
  www.2cto.com  
5. 重建索引,将原有表中的索引再建到System.Test表中。 
 
6. 检查分区 
Sql代码  
   
  select decode(A,'1','1','2','1','3','1','4','1','5','1',a),  
count('x') n  
  from System.Test  
 group by decode(A,'1','1','2','1','3','1','4','1','5','1',a)  
 order by decode(A,'1','1','2','1','3','1','4','1','5','1',a);  
 
select count('x')  n1 from System.Test partition (p1);  
  
select count('x')  n2 from System.Test partition (p2);  
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
oracle按时间创建分区表
oracle表分区
Oracle数据库中分区表的操作方法
详解ORACLE数据库的分区表
如何保持Oracle数据库的优良性能
Oracle数据库优化的方案和实践
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服