1.Rename table
alter
table SCOTT.TAB1 rename to TAB1_NOPART;
2. Tạo
bảng partition:
CREATE
TABLE SCOTT.TAB1(
SUB_ID
NUMBER,
BILL_ITEM_ID
NUMBER
)
TABLESPACE
TMP_DUMP
PARTITION
BY RANGE (PDATE)
(
PARTITION DATA20180101 VALUES LESS THAN
(TO_DATE(' 2019-01-02 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIAN'))
TABLESPACE DATA201301
)
Add
thêm partition:
DECLARE
v_nam NUMBER (4) := 2019;
v_tablename VARCHAR2 (50) := 'TAB1';
v_date_from
date :=
to_date('02/01/2019','dd/mm/yyyy');
v_date_to
date :=
to_date('31/12/2019','dd/mm/yyyy');
v_numday
number(5);
v_tablespace varchar2(50):='DATA';
BEGIN
v_numday:=v_date_to-v_date_from;
FOR i IN 0 .. v_numday
LOOP
DBMS_OUTPUT.put_line ('alter table '||
v_tablename || ' add PARTITION DATA'||to_char(v_date_from+i,'YYYYMMDD')||'
VALUES LESS THAN (TO_DATE('''|| to_char(v_date_from+i+1,'YYYY-MM-DD')||'
00:00:00'', ''SYYYY-MM-DD HH24:MI:SS'', ''NLS_CALENDAR=GREGORIAN'')) LOGGING
TABLESPACE '||v_tablespace||to_date(v_date_from+i,'YYYY')||';');
END LOOP;
END;
3.
Insert dữ liệu
insert
/*+append nologging parallel(a,16)*/
into SCOTT.TAB1 a select /*+ parallel(b,16) */ * from SCOTT.TAB1_NOPART b;
commit;
--Monitoring
qua trinh insert
select /*+
parallel(b,16) */ count(*) from
SCOTT.TAB1_NOPART b;
select /*+
parallel(b,16) */ count(*) from
SCOTT.TAB1 b;
4.Tạo
Index
create
index SCOTT.TAB1_IDX1 on SCOTT.TAB1
(LOAD_DATE, MSISDN, STATUS) tablespace INDX local nologging parallel 16
online;
alter
index SCOTT.TAB1_IDX1 noparallel;