为什么使用自动分区?
在oracle11g之前,oracle是不支持自动分区功能的,这就可能导致我们系统在运行一段时间之后,就需要看看分区是否创建或者写触发器进行创建分区,否则就会导致数据无法入库或者大量的数据全部都进入了默认分区。维护起来容易出错而且复杂。但oracle11g出现了通过interval自动分区,这就使我们系统在使用分区功能时更加自如。
如何自动创建分区?
oracle本身提供了多种创建分区的功能,比如创建表的同时创建分区,或者创建好分区把数据导入进去,在或者在线定义分区,本文我主要介绍如何range模式下自动创建分区。
创建分区具体实例(可直接运行)
CREATE TABLE "T_PART_TABLE"
("ID" VARCHAR2(64),
"PERSOID" NUMBER,
"CODE" VARCHAR2(64),
"NAME" VARCHAR2(64),
"DEPT" VARCHAR2(64),
"LOG_TIME" NUMBER,
"LOG_TYPE" NUMBER,
"CONTENT" VARCHAR2(1024),
"RESULT" VARCHAR2(2),
"SN" VARCHAR2(128),
"DEPT_ID" NUMBER,
"BLACK_FLAG" VARCHAR2(2 BYTE),
"CREATE_TIME" Date)
PARTITION BY RANGE (CREATE_TIME) interval (numtodsinterval (1,'DAY'))
(
PARTITION part_p180613 VALUES LESS THAN (TO_DATE('2018-6-13', 'yyyy-mm-dd'))
);
COMMENT ON COLUMN "T_PART_TABLE"."ID" IS '主键';
COMMENT ON COLUMN "T_PART_TABLE"."PERSOID" IS 'id';
COMMENT ON COLUMN "T_PART_TABLE"."CODE" IS '编码';
COMMENT ON COLUMN "T_PART_TABLE"."NAME" IS '姓名';
COMMENT ON COLUMN "T_PART_TABLE"."DEPT" IS '部门';
COMMENT ON COLUMN "T_PART_TABLE"."LOG_TIME" IS '日志时间';
COMMENT ON COLUMN "T_PART_TABLE"."LOG_TYPE" IS '类型 ';
COMMENT ON COLUMN "T_PART_TABLE"."CONTENT" IS '内容';
COMMENT ON COLUMN "T_PART_TABLE"."RESULT" IS '';
COMMENT ON COLUMN "T_PART_TABLE"."SN" IS '证书sn';
COMMENT ON COLUMN "T_PART_TABLE"."DEPT_ID" IS '部门id';
CREATE UNIQUE INDEX "T_PART_TABLE_PK" ON "T_PART_TABLE" ("ID");
ALTER TABLE "T_PART_TABLE" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "T_PART_TABLE" ADD CONSTRAINT "T_PART_TABLE_PK" PRIMARY KEY ("ID") ENABLE;