简单说说Oracle分区(1)(2)
四、分区表操作 --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
- select * from v$option s order by s.PARAMETER desc
--创建表空间
- CREATE TABLESPACE "PARTION_03"
- LOGGING
- DATAFILE 'D:\ORACLE\ORADATA\JZHUA\PARTION_03.dbf' SIZE 50M
- EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
--删除表空间
- drop tablespace partion_01
--范围 分区技术
- create table Partition_Test
- (
- PID number not null,
- PITEM varchar2(200),
- PDATA date not null
- )
- partition by range(PID)
- (
- partition part_01 values less than(50000) tablespace dinya_space01,
- partition part_02 values less than(100000) tablespace dinya_space02,
- partition part_03 values less than(maxvalue) tablespace dinya_space03
- )
- create table Partition_TTest
- (
- PID number not null,
- PITEM varchar2(200),
- PDATA date not null
- )
- partition by range(PDATA)
- (
- partition part_t01 values less than(to_date('2004-01-01','yyyy-mm-dd')) tablespace dinya_space01,
- partition part_t02 values less than(to_date('2008-01-01','yyyy-mm-dd')) tablespace dinya_space02,
- partition part_t03 values less than(maxvalue) tablespace dinya_space03
- )
- insert into Partition_Test(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h
- select * from Partition_Test partition(part_01) t where t.pid = '1961'
--hash 分区技术
- create table Partition_HashTest
- (
- PID number not null,
- PITEM varchar2(200),
- PDATA date not null
- )
- partition by hash(PID)
- (
- partition part_h01 tablespace dinya_space01,
- partition part_h02 tablespace dinya_space02,
- partition part_h03 tablespace dinya_space03
- )
- insert into Partition_HashTest(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h
- select * from Partition_HashTest partition(part_h03) t where t.pid = '1961'
--复合分区技术
- create table Partition_FHTest
- (
- PID number not null,
- PITEM varchar2(200),
- PDATA date not null
- )
- partition by range(PDATA) subpartition by hash(PID) subpartitions 3 store in (dinya_space01,dinya_space02,dinya_space03)
- (
- partition part_fh01 values less than(to_date('2004-01-01','yyyy-mm-dd')) tablespace dinya_space01,
- partition part_fh02 values less than(to_date('2008-01-01','yyyy-mm-dd')) tablespace dinya_space02,
- partition part_fh03 values less than(maxvalue) tablespace dinya_space03
- )
- insert into Partition_FHTest(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h
- select * from Partition_FHTest partition(part_fh02) t where t.pid = '1961'
- select * from Partition_FHTest partition(part_fh03) t
--速度比较
- select * from st_handle h where h.rectime > to_date('2008-01-01','yyyy-mm-dd');
- select * from Partition_FHTest partition(part_fh03) t where t.pdata > to_date('2008-01-01','yyyy-mm-dd');
--分区表操作
--增加一个分区
- alter table Partition_Test add partition part_05 values less than (10020) tablespace dinya_space03
--查询分区数据
- select * from Partition_FHTest partition(part_fh02) t
--修改分区里的数据
- update Partition_FHTest partition(part_fh02) t set t.PITEM = 'JZHUA' where t.pid = '1961'
--删除分区里的数据
- delete from Partition_FHTest partition(part_fh02) t where t.pid = '1961'
--合并分区
- create table Partition_HB
- (
- PID number not null,
- PITEM varchar2(200),
- PDATA date not null
- )
- partition by range(PID)
- (
- partition part_01 values less than(50000) tablespace dinya_space01,
- partition part_02 values less than(100000) tablespace dinya_space02,
- partition part_03 values less than(maxvalue) tablespace dinya_space03
- )
- insert into Partition_HB(PID,PITEM,PDATA) select h.id,h.userid,h.rectime from st_handle h
- select * from Partition_HB partition(part_03) t where t.pid = '100001'
- alter table Partition_HB merge partitions part_01,part_02 into partition part_02;
--拆分分区
- -- spilt partition 分区名 at(这里是一个临界区,比如:50000就是说小于50000的放在part_01,而大于50000的放在part_02中)
- alter table Partition_HB split Partition part_02 at (50000) into (Partition part_01 tablespace dinya_space01, Partition part_02 tablespace dinya_space02);
--更改分区名
- alter table Partition_HB rename Partition part_01_test to part_02;
精彩图集
精彩文章