PLSQL里操作,直接上代码:

 
  
  1. --目的:用表分区转换大表数据,演示中只是用5000条数据; 
  2. --建表T 
  3. create table t(id number,name varchar2(10)); 
  4. insert into t select rownum+4,'1,2,3,4' from dual connect by rownum<=5000; 
  5. commit
  6. select count(1) from t ; 
  7.   
  8. --创建表空间 
  9. create tablespace ts_1 datafile 'E:\oracle\product\10.2.0\oradata\orcl\ts_1.dbf' size 50m reuse; 
  10. create tablespace ts_2 datafile 'E:\oracle\product\10.2.0\oradata\orcl\ts_2.dbf' size 50m reuse; 
  11. create tablespace ts_3 datafile 'E:\oracle\product\10.2.0\oradata\orcl\ts_3.dbf' size 50m reuse; 
  12.  
  13. --创建新表及分区 
  14. create table t_new partition by range(id)( 
  15. partition p1 values less than (2000) tablespace ts_1, 
  16. partition p2 values less than (4000) tablespace ts_2, 
  17. partition p3 values less than (maxvalue) tablespace ts_3) 
  18. as select * from t; 
  19.  
  20. --删除老表并更换名字 
  21. truncate table t; 
  22. drop table t; 
  23. alter table t_new rename to t; 
  24.  
  25. --检查各分区的数据 
  26. select count(*) from t partition (p1); 
  27. select count(*) from t partition (p2); 
  28. select count(*) from t partition (p3);