Oracle创建分区表(Partition Table)

1、分区表类别

1.1、范围分区表;

1.2、列表分区表;

1.3、哈希分区表;

1.4、组合分区表;

 

1.1 范围分区表

CREATE TABLE range_Partition_Table(
     range_key_column DATE,
     NAME VARCHAR2(20),
     ID integer
 ) PARTITION BY RANGE(range_key_column)
 (
     PARTITION PART_202007 VALUES LESS THAN (TO_DATE('2020-07-1 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE tbs01,
     PARTITION PART_202008 VALUES LESS THAN (TO_DATE('2020-08-1 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE tbs02,
     PARTITION PART_202009 VALUES LESS THAN (TO_DATE('2020-09-1 00:00:00','yyyy-mm-dd hh24:mi:ss')) TABLESPACE tbs03
);

1.2、列表分区表

CREATE TABLE list_Partition_Table(
     NAME VARCHAR2(10),
     DATA VARCHAR2(20)
)PARTITION BY LIST(NAME)
(
      PARTITION PART_01 VALUES('ME','PE','QC','RD'),
      PARTITION PART_02 VALUES('SMT','SALE')
);

1.3 哈希分区表

CREATE TABLE hash_Partition_Table(
      hash_key_column VARCHAR2(30),
      DATA VARCHAR2(20)
) PARTITION BY HASH(hash_key_cloumn)
(
     PARTITION PART_0001,
     PARTITION PART_0002,
     PARTITION PART_0003,
     PARTITION PART_0004,
     PARTITION PART_0005
);

1.4 组合分区表

CREATE TABLE range_hash_Partition_Table(
 range_column_key DATE,
 hash_column_key INT,
 DATA VARCHAR2(20)
)
PARTITION BY RANGE(range_column_key)
SUBPARTITION BY HASH(hash_column_key) SUBPARTITIONS 2
(
   PARTITION PART_202008 VALUES LESS THAN (TO_DATE('2020-08-01','yyyy-mm-dd'))(
      SUBPARTITION SUB_1,
      SUBPARTITION SUB_2,
      SUBPARTITION SUB_3
   ),
   PARTITION 202009 VALUES LESS THAN (TO_DATE('2020-09-01','yyyy-mm-dd'))(
      SUBPARTITION SUB_1,
      SUBPARTITION SUB_2
   )
);

你可能感兴趣的:(数据库相关,项目经验积累)