11G普通分割槽錶轉化為間隔分割槽表
阿新 • • 發佈:2019-02-07
--建立普通範圍分割槽表
CREATE TABLE clg_range_table2
(req_num NUMBER NOT NULL,
req_date DATE NOT NULL,
status VARCHAR2(2) not NULL
)
PARTITION BY RANGE(req_date)
(PARTITION p1 VALUES LESS THAN(to_date('20140101','yyyymmdd')) TABLESPACE p1,
PARTITION p2 VALUES LESS THAN (to_date('20140201','yyyymmdd')) TABLESPACE p2,
PARTITION p3 VALUES LESS THAN (to_date('20140301','yyyymmdd')) TABLESPACE p3,
PARTITION p4 VALUES LESS THAN (MAXVALUE) TABLESPACE p4
)
--新增表空間
create tablespace p1 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p1.dbf' size 10M;
create tablespace p2 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p2.dbf' size 10M;
create tablespace p3 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p3.dbf' size 10M;
create tablespace p4 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p4.dbf' size 10M;
--將分割槽錶轉化為間隔分割槽
alter table CLG_RANGE_TABLE2 drop partition p4;
alter table CLG_RANGE_TABLE2 set interval(numtodsinterval(1,'DAY'))
alter table CLG_RANGE_TABLE2 set STORE IN (P1,P2,P3,P4)
--測試
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE-1,'Y');
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE-2,'Y');
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE,'Y');
COMMIT;
--查詢
SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME FROM USER_TAB_PARTITIONS WHERE TABLE_NAME=UPPER('clg_range_table2');
--禁用interval
alter table CLG_RANGE_TABLE2 set interval();
alter table CLG_RANGE_TABLE2 add partition pmax values LESS THAN (MAXVALUE) TABLESPACE p4;
CREATE TABLE clg_range_table2
(req_num NUMBER NOT NULL,
req_date DATE NOT NULL,
status VARCHAR2(2) not NULL
)
PARTITION BY RANGE(req_date)
(PARTITION p1 VALUES LESS THAN(to_date('20140101','yyyymmdd')) TABLESPACE p1,
PARTITION p2 VALUES LESS THAN (to_date('20140201','yyyymmdd')) TABLESPACE p2,
PARTITION p3 VALUES LESS THAN (to_date('20140301','yyyymmdd')) TABLESPACE p3,
PARTITION p4 VALUES LESS THAN (MAXVALUE) TABLESPACE p4
)
--新增表空間
create tablespace p1 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p1.dbf' size 10M;
create tablespace p2 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p2.dbf' size 10M;
create tablespace p3 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p3.dbf' size 10M;
create tablespace p4 datafile 'D:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\PORD\p4.dbf' size 10M;
--將分割槽錶轉化為間隔分割槽
alter table CLG_RANGE_TABLE2 drop partition p4;
alter table CLG_RANGE_TABLE2 set interval(numtodsinterval(1,'DAY'))
alter table CLG_RANGE_TABLE2 set STORE IN (P1,P2,P3,P4)
--測試
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE-1,'Y');
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE-2,'Y');
INSERT INTO clg_range_table2 VALUES(20170101,SYSDATE,'Y');
COMMIT;
--查詢
SELECT TABLE_NAME,PARTITION_NAME,TABLESPACE_NAME FROM USER_TAB_PARTITIONS WHERE TABLE_NAME=UPPER('clg_range_table2');
--禁用interval
alter table CLG_RANGE_TABLE2 set interval();
alter table CLG_RANGE_TABLE2 add partition pmax values LESS THAN (MAXVALUE) TABLESPACE p4;