龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 数据库类 > Oracle 技术 >

简单说说Oracle分区(1)(2)

时间:2011-04-12 23:18来源:未知 作者:admin 点击:
分享到:
四、分区表操作 --Partitioning 是否为true select * from v$ option s order by s.PARAMETER desc --创建表空间 CREATE TABLESPACE PARTION_03 LOGGING DATAFILE 'D:\ORACLE\ORADATA\JZHUA\PARTION_

四、分区表操作

--Partitioning 是否为true

  1. select * from v$option s order by s.PARAMETER desc  

--创建表空间

  1. CREATE TABLESPACE "PARTION_03"   
  2. LOGGING   
  3. DATAFILE 'D:\ORACLE\ORADATA\JZHUA\PARTION_03.dbf' SIZE 50M   
  4. EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO  

--删除表空间

  1. drop tablespace partion_01  

--范围 分区技术

  1. create table Partition_Test   
  2. (   
  3. PID number not null,   
  4. PITEM varchar2(200),   
  5. PDATA date not null   
  6. )   
  7. partition by range(PID)   
  8. (   
  9. partition part_01 values less than(50000) tablespace dinya_space01,   
  10. partition part_02 values less than(100000) tablespace dinya_space02,   
  11. partition part_03 values less than(maxvalue) tablespace dinya_space03   
  12. )   
  13. create table Partition_TTest   
  14. (   
  15. PID number not null,   
  16. PITEM varchar2(200),   
  17. PDATA date not null   
  18. )   
  19. partition by range(PDATA)   
  20. (   
  21. partition part_t01 values less than(to_date('2004-01-01','yyyy-mm-dd')) tablespace dinya_space01,   
  22. partition part_t02 values less than(to_date('2008-01-01','yyyy-mm-dd')) tablespace dinya_space02,   
  23. partition part_t03 values less than(maxvalue) tablespace dinya_space03   
  24. )   
  25. insert into Partition_Test(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h   
  26. select * from Partition_Test partition(part_01) t where t.pid = '1961'  

--hash 分区技术

  1. create table Partition_HashTest   
  2. (   
  3. PID number not null,   
  4. PITEM varchar2(200),   
  5. PDATA date not null   
  6. )   
  7. partition by hash(PID)   
  8. (   
  9. partition part_h01 tablespace dinya_space01,   
  10. partition part_h02 tablespace dinya_space02,   
  11. partition part_h03 tablespace dinya_space03   
  12. )   
  13. insert into Partition_HashTest(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h   
  14. select * from Partition_HashTest partition(part_h03) t where t.pid = '1961'  

--复合分区技术

  1. create table Partition_FHTest   
  2. (   
  3. PID number not null,   
  4. PITEM varchar2(200),   
  5. PDATA date not null   
  6. )   
  7. partition by range(PDATA) subpartition by hash(PID) subpartitions 3 store in (dinya_space01,dinya_space02,dinya_space03)   
  8. (   
  9. partition part_fh01 values less than(to_date('2004-01-01','yyyy-mm-dd')) tablespace dinya_space01,   
  10. partition part_fh02 values less than(to_date('2008-01-01','yyyy-mm-dd')) tablespace dinya_space02,   
  11. partition part_fh03 values less than(maxvalue) tablespace dinya_space03   
  12. )   
  13. insert into Partition_FHTest(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h   
  14. select * from Partition_FHTest partition(part_fh02) t where t.pid = '1961'   
  15. select * from Partition_FHTest partition(part_fh03) t  

--速度比较

  1. select * from st_handle h where h.rectime > to_date('2008-01-01','yyyy-mm-dd');   
  2. select * from Partition_FHTest partition(part_fh03) t where t.pdata > to_date('2008-01-01','yyyy-mm-dd');  

--分区表操作

--增加一个分区

  1. alter table Partition_Test add partition part_05 values less than (10020) tablespace dinya_space03   

--查询分区数据 

  1. select * from Partition_FHTest partition(part_fh02) t 

--修改分区里的数据

  1. update Partition_FHTest partition(part_fh02) t set t.PITEM = 'JZHUA' where t.pid = '1961'   

--删除分区里的数据

  1. delete from Partition_FHTest partition(part_fh02) t where t.pid = '1961'  

--合并分区

  1. create table Partition_HB   
  2. (   
  3. PID number not null,   
  4. PITEM varchar2(200),   
  5. PDATA date not null   
  6. )   
  7. partition by range(PID)   
  8. (   
  9. partition part_01 values less than(50000) tablespace dinya_space01,   
  10. partition part_02 values less than(100000) tablespace dinya_space02,   
  11. partition part_03 values less than(maxvalue) tablespace dinya_space03   
  12. )   
  13. insert into Partition_HB(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h   
  14. select * from Partition_HB partition(part_03) t where t.pid = '100001'   
  15. alter table Partition_HB merge partitions part_01,part_02 into partition part_02;  

--拆分分区

  1. -- spilt partition 分区名 at(这里是一个临界区,比如:50000就是说小于50000的放在part_01,而大于50000的放在part_02中)   
  2. alter table Partition_HB split Partition part_02 at (50000) into (Partition part_01 tablespace dinya_space01, Partition part_02 tablespace dinya_space02);  

--更改分区名

  1. alter table Partition_HB rename Partition part_01_test to part_02;  

精彩图集

赞助商链接