oracle11 创建自动分区表

--1,重命名原表 SCAN_LOG 为SCAN_LOG_BCK
--2,创建按天自动分区的库存日志表,从2019-03-01日开始
create table SCAN_LOG
(
  DOC_ID VARCHAR2(20), 
	SDOC_ID VARCHAR2(40), 
	SCAN_SITE VARCHAR2(20), 
	SCAN_TYPE VARCHAR2(20), 
    SUCCESS VARCHAR2(80),
	DO_TIME DATE
)
PARTITION BY RANGE (DO_TIME) INTERVAL (NUMTODSINTERVAL (1, 'day'))
(partition part_t01 values less than(to_date('2019-03-01', 'yyyy-mm-dd')));

CREATE INDEX "GGS"."INDEX_SCANLOG_DOCID"
ON "GGS"."SCAN_LOG" ("DOC_ID" ASC);

CREATE INDEX "GGS"."INDEX_SCANLOG_SITE"
ON "GGS"."SCAN_LOG" ("SCAN_SITE" ASC);

--3,查看分区
select * from user_tab_partitions
where table_name='SCAN_LOG';

--4,转移数据到分区表
insert into SCAN_LOG(
	doc_id,sdoc_id,scan_site,scan_type,success,do_time
)
select doc_id,sdoc_id,scan_site,scan_type,success,do_time from SCAN_LOG_BCK;
--5,删除原表
drop table SCAN_LOG_BCK;

你可能感兴趣的:(理论笔记,oracle,分区表)