zoukankan      html  css  js  c++  java
  • 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); 
  • 相关阅读:
    每天玩转3分钟 MyBatis-Plus
    每天玩转3分钟 MyBatis-Plus
    每天玩转3分钟 MyBatis-Plus
    git仓库管理
    【SpringCloud之pigx框架学习之路 】2.部署环境
    【SpringCloud之pigx框架学习之路 】1.基础环境安装
    Ubuntu 14.04 安装mysql
    Netflix是什么,与Spring Cloud有什么关系
    现学现用-我的第三个小小小私活
    申请微信小游戏账号
  • 原文地址:https://www.cnblogs.com/tangkai/p/2917100.html
Copyright © 2011-2022 走看看