現在12C 只要一條指令就可以完成新增刪除分割 partition 的動作,就不用麻煩的下多條指令
以下是對新增 Partition 的簡單示範
先建立Partition
- create table test_par2
- (
- seq_id number,
- txt varchar2(4000 char),
- t_time date
- )
- partition by range (t_time)
- (
- partition p_time_2014_06 values less than (to_date(' 2014-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
- partition p_time_2014_07 values less than (to_date(' 2014-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
- );
- SQL> select partition_name from dba_tab_partitions where table_name = 'TEST_PAR2';
- PARTITION_NAME
- ---------------
- P_TIME_2014_07
- P_TIME_2014_06
新增 Partition 分區
- ALTER TABLE test_par2 ADD
- PARTITION P_TIME_2014_08 VALUES LESS THAN (TO_DATE(' 2014-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
- PARTITION P_TIME_2014_09 VALUES LESS THAN (TO_DATE(' 2014-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
- PARTITION P_TIME_2014_10 VALUES LESS THAN (TO_DATE(' 2014-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'));
- SQL> select partition_name from dba_tab_partitions where table_name = 'TEST_PAR2';
- PARTITION_NAME
- ---------------
- P_TIME_2014_07
- P_TIME_2014_06
- P_TIME_2014_08
- P_TIME_2014_09
- P_TIME_2014_10
新增成功,只要 Maxvalue 分區沒建立,你就可以新增多個 Partition 進去
對於刪除 Partition 的簡單示範
- SQL> alter table check_db.test_par2 drop partitions p_time_2014_09,p_time_2014_10;
- 已更改表格.
- SQL>
- SQL> alter table check_db.test_par2 truncate partitions p_time_2014_09,p_time_2014_10;
- 已更改表格.
- SQL>
對於分割 Partition 的簡單示範
- create table test_par2
- (
- seq_id number,
- txt varchar2 (4000 char),
- nb number
- )
- partition by range (nb)
- (
- partition p_01 values less than (1000),
- partition p_02 values less than (2000),
- partition p_max values less than (maxvalue)
- );
- alter table test_par2 split partition p_max
- into (partition p3 values less than (2500),
- partition p4 values less than (4000),
- partition p_max);
查看是否成功
- SQL> select partition_name, high_value from dba_tab_partitions
- 2 where table_name = 'TEST_PAR2';
- PARTITION_NAME HIGH_VALUE
- ------------------------ ------------------------------
- P_03 2500
- P_04 4000
- P_01 1000
- P_02 2000
- P_MAX MAXVALUE
對於合併 Partition 的簡單示範
- alter table test_par2 merge partitions p2,p3,p4 into partition p_sum;
- SQL> select partition_name, high_value from dba_tab_partitions
- 2 where table_name = 'TEST_PAR2';
- PARTITION_NAME HIGH_VALUE
- ----------------------------- ------------------------
- P_SUM 4000
- P_01 1000
- P_MAX1 MAXVALUE
合併後的 HIGH_VALUE 會是指定 Partition 的最大值
沒有留言:
張貼留言