You can use the ALTER TABLE...RENAME PARTITION command to rename a table partition.
Overview
The command has two forms.
ALTER TABLE table_name RENAME PARTITION partition_name TO new_name;
ALTER TABLE table_name RENAME SUBPARTITION subpartition_name TO new_name;
The ALTER TABLE...RENAME PARTITION command makes no distinctions between a partition
and a subpartition:
- You can rename a partition by using the RENAME PARTITION or RENAME SUBPARTITION clause.
- You can rename a subpartition by using the RENAME PARTITION or RENAME SUBPARTITION clause.
Description
The ALTER TABLE...RENAME PARTITION and ALTER TABLE...RENAME SUBPARTITION commands renames a partition or subpartition. You must own the specified table to run ALTER TABLE...RENAME PARTITION or ALTER TABLE...RENAME SUBPARTITION.
Parameters
Parameter | Description |
---|---|
table_name | The name (optionally schema-qualified) of the table in which the partition resides. |
partition_name | The name of the partition or subpartition to be renamed. |
new_name | The new name of the partition or subpartition. |
Example - rename a partition
The following command creates a list-partitioned table named sales:
CREATE TABLE sales
(
dept_no number,
part_no varchar2,
country varchar2(20),
date date,
amount number
)
PARTITION BY LIST(country)
(
PARTITION europe VALUES('FRANCE', 'ITALY'),
PARTITION asia VALUES('INDIA', 'PAKISTAN'),
PARTITION americas VALUES('US', 'CANADA')
);
Querying the ALL_TAB_PARTITIONS view displays the partition names:
acctg=# SELECT partition_name, high_value FROM ALL_TAB_PARTITIONS;
partition_name | high_value
----------------+---------------------
europe | 'FRANCE', 'ITALY'
asia | 'INDIA', 'PAKISTAN'
americas | 'US', 'CANADA'
(3 rows)
The following command renames the americas partition to n_america:
ALTER TABLE sales
RENAME PARTITION americas TO n_america;
Querying the ALL_TAB_PARTITIONS view will show that the partition is renamed:
acctg=# SELECT partition_name, high_value FROM ALL_TAB_PARTITIONS;
partition_name | high_value
----------------+---------------------
europe | 'FRANCE', 'ITALY'
asia | 'INDIA', 'PAKISTAN'
n_america | 'US', 'CANADA'
(3 rows)