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 |
| Yes | The name of the target composite partitioned table. |
|
| Yes | The name of the subpartition to truncate. |
|
| No | This clause is parsed for Oracle syntax compatibility but is ignored and has no effect on storage. |
|
Notes
You must be the table owner or have the
ALTERpermission on the table.TRUNCATE SUBPARTITIONacquires a table-level exclusive lockAccessExclusiveLock. 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 SUBPARTITIONimplicitly commits the current transaction. After the command is executed, the deleted data cannot be recovered usingROLLBACK. Back up your data before you perform this operation.TRUNCATE SUBPARTITIONis 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).
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
ALTER TABLE... DROP SUBPARTITION: Deletes a subpartition definition and the data it contains.
ALTER TABLE TRUNCATE PARTITION: Deletes the data from a primary partition and all its subpartitions.
ALTER TABLE ADD SUBPARTITION: Adds a new subpartition to an existing primary partition.
ALTER TABLE SPLIT SUBPARTITION: Splits one subpartition into two subpartitions.