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 following example shows an exchange partition scenario for a list-list partitioned table.
CREATE TABLE customers_apac ( id NUMBER , name VARCHAR2(50) , email VARCHAR2(100) , region VARCHAR2(4) , credit_rating VARCHAR2(1) ) PARTITION BY LIST (credit_rating) ( PARTITION poor VALUES ('P') , PARTITION mediocre VALUES ('C') , PARTITION good VALUES ('G') , PARTITION excellent VALUES ('E') );
Populate the table with APAC customers. Then create a list-list partitioned table:
CREATE TABLE customers ( id NUMBER , name VARCHAR2(50) , email VARCHAR2(100) , region VARCHAR2(4) , credit_rating VARCHAR2(1) ) PARTITION BY LIST (region) SUBPARTITION BY LIST (credit_rating) SUBPARTITION TEMPLATE ( SUBPARTITION poor VALUES ('P') , SUBPARTITION mediocre VALUES ('C') , SUBPARTITION good VALUES ('G') , SUBPARTITION excellent VALUES ('E') ) (PARTITION americas VALUES ('AMER') , PARTITION emea VALUES ('EMEA') , PARTITION apac VALUES ('APAC') );
It is important that the partitioning key in the customers_apac
table matches the subpartitioning key in the customers
table.
Next, exchange the apac
partition.
ALTER TABLE customers EXCHANGE PARTITION apac WITH TABLE customers_apac WITH VALIDATION;