The semantics of the ALTER
TABLE
EXCHANGE
PARTITION
statement are the same as described previously in "Exchanging a Hash Partitioned Table with a *-Hash Partition". The example below shows the orders
table, which is interval partitioned by order_date
, and subpartitioned by range on order_total
. The example shows how to exchange a single monthly interval with a range-partitioned table.
CREATE TABLE orders_mar_2007 ( id NUMBER , cust_id NUMBER , order_date DATE , order_total NUMBER ) PARTITION BY RANGE (order_total) ( PARTITION p_small VALUES LESS THAN (1000) , PARTITION p_medium VALUES LESS THAN (10000) , PARTITION p_large VALUES LESS THAN (100000) , PARTITION p_extraordinary VALUES LESS THAN (MAXVALUE) );
Populate the table with orders for March 2007. Then create an interval-range partitioned table:
CREATE TABLE orders ( id NUMBER , cust_id NUMBER , order_date DATE , order_total NUMBER ) PARTITION BY RANGE (order_date) INTERVAL (NUMTOYMINTERVAL(1,'MONTH')) SUBPARTITION BY RANGE (order_total) SUBPARTITION TEMPLATE ( SUBPARTITION p_small VALUES LESS THAN (1000) , SUBPARTITION p_medium VALUES LESS THAN (10000) , SUBPARTITION p_large VALUES LESS THAN (100000) , SUBPARTITION p_extraordinary VALUES LESS THAN (MAXVALUE) ) (PARTITION p_before_2007 VALUES LESS THAN (TO_DATE('01-JAN-2007','dd- MON-yyyy')));
It is important that the partitioning key in the orders_mar_2007
table matches the subpartitioning key in the orders
table.
Next, exchange the partition. Because an interval partition is to be exchanged, the partition is first locked to ensure that the partition is created.
LOCK TABLE orders PARTITION FOR (TO_DATE('01-MAR-2007','dd-MON-yyyy')) IN SHARE MODE; ALTER TABLE orders EXCHANGE PARTITION FOR (TO_DATE('01-MAR-2007','dd-MON-yyyy')) WITH TABLE orders_mar_2007 WITH VALIDATION;