All Products
Search
Document Center

PolarDB:ALTER TABLE TRUNCATE SUBPARTITION

Last Updated:Oct 23, 2025

Deletes all data from a specified subpartition in a composite partitioned table. This operation permanently removes the data but retains the subpartition structure. Before you run this command, ensure that the data is no longer needed or has been backed up.

Synopsis

ALTER TABLE table_name 
  TRUNCATE SUBPARTITION subpartition_name 
  [{DROP|REUSE} STORAGE]

Parameters

Parameter

Required

Description

Example

table_name

Yes

The name of the target composite partitioned table.

customer_data

subpartition_name

Yes

The name of the subpartition to truncate.

p_2022_asia

{DROP|REUSE} STORAGE

No

This clause is parsed for Oracle syntax compatibility but is ignored and has no effect on storage.

DROP STORAGE/

REUSE STORAGE

Notes

  • You must be the table owner or have the ALTER permission on the table.

  • TRUNCATE SUBPARTITION acquires a table-level exclusive lock AccessExclusiveLock. This lock blocks all Data Manipulation Language (DML) and most Data Definition Language (DDL) operations on the table. Run this statement during off-peak hours and allow sufficient time for it to complete to avoid blocking other critical operations on the table.

  • As a DDL operation, TRUNCATE SUBPARTITION implicitly commits the current transaction. After the command is executed, the deleted data cannot be recovered using ROLLBACK. Back up your data before you perform this operation.

  • TRUNCATE SUBPARTITION is a metadata operation that includes file deletion. It can be completed in seconds, even for tables with hundreds of millions of records. The I/O, CPU, and memory overhead is extremely low.

Examples

This example shows how to delete data from the subpartition for user data from the Asia region for the year 2022. The example uses a customer table that is composite-partitioned by registration year (RANGE) and user region (LIST).

Prepare the environment

This step creates a composite partitioned table named customer_data. The table is range-partitioned by registration year (p_2022) and then list-subpartitioned by user region (p_2022_asia and p_2022_europe). Test data is then inserted into these two subpartitions.

-- Create a composite partitioned table
CREATE TABLE customer_data (
    customer_id  INT NOT NULL,
    region       VARCHAR2(10),
    reg_date     DATE
)
PARTITION BY RANGE (reg_date)
SUBPARTITION BY LIST (region)
(
    PARTITION p_2022 VALUES LESS THAN (TO_DATE('2023-01-01', 'YYYY-MM-DD'))
    (
        SUBPARTITION p_2022_asia    VALUES ('Asia'),
        SUBPARTITION p_2022_europe  VALUES ('Europe')
    )
);

-- Insert data
INSERT INTO customer_data VALUES (101, 'Asia', TO_DATE('2022-06-10', 'YYYY-MM-DD'));
INSERT INTO customer_data VALUES (102, 'Europe', TO_DATE('2022-07-20', 'YYYY-MM-DD'));

Perform the pre-check

Before you truncate the subpartition, confirm that the data is backed up. Then, check the structure and data of the target subpartition.

-- Important: Before you empty the subpartition, make sure you have backed up the relevant data.

-- Check the subpartition structure to confirm that the p_2022_asia subpartition exists.
SELECT SUBPARTITION_NAME FROM USER_TAB_SUBPARTITIONS WHERE TABLE_NAME = 'CUSTOMER_DATA';

-- Check the subpartition data to confirm that it contains data.
SELECT COUNT(*) FROM customer_data SUBPARTITION (p_2022_asia);

Run the command

Run TRUNCATE SUBPARTITION to truncate the p_2022_asia subpartition.

ALTER TABLE customer_data TRUNCATE SUBPARTITION p_2022_asia;

Verify the result

Verify that the subpartition structure is retained and that the data has been deleted.

-- Verify the structure: Confirm that the subpartition definition still exists.
SELECT SUBPARTITION_NAME FROM USER_TAB_SUBPARTITIONS 
WHERE TABLE_NAME = 'CUSTOMER_DATA';
-- The query result should include p_2022_asia.

-- Verify the data: Confirm that the data in the subpartition has been emptied.
SELECT COUNT(*) FROM customer_data SUBPARTITION (p_2022_asia);
-- The query result is 0.

FAQ

Q1: What is the difference between TRUNCATE SUBPARTITION and DROP SUBPARTITION?

TRUNCATE SUBPARTITION deletes the data from a subpartition but retains its definition. DROP SUBPARTITION deletes both the subpartition definition and its data.

Q2: Can data be recovered after TRUNCATE SUBPARTITION is executed?

No. TRUNCATE is a DDL operation that permanently deletes data. By default, it is not recorded in the transaction log. The data cannot be recovered using standard methods such as rollback or flashback.

Q3: What is the difference between TRUNCATE SUBPARTITION and DELETE FROM ... SUBPARTITION?

TRUNCATE SUBPARTITION is an efficient DDL operation that directly deletes data by releasing data blocks and cannot be rolled back. DELETE is a DML operation that deletes data row by row. It records logs, can be rolled back, and fires delete triggers.

Q4: Why do I get the error "ORA-02149: relation ... does not exist"?

This error occurs because the subpartition name does not exist or the case of the specified name does not match the actual name. Names are case-sensitive. To confirm the name, perform the pre-check.

Q5: Why do I get the error "ORA-01031: insufficient privileges"?

This error occurs because the user who runs the command does not have the ALTER permission on the target table. Contact your database administrator to grant the required permission.

Related SQL statements