Removes all data from a specified partition of a partitioned table. This operation permanently deletes the data but retains the partition 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 PARTITION partition_name
[{DROP|REUSE} STORAGE]Parameters
Parameter | Required | Description | Example |
| Yes | The name of the partitioned table. |
|
| Yes | The name of the partition 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 a privileged user to run this command.
TRUNCATE PARTITIONacquires 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.TRUNCATE PARTITIONis a metadata-only operation combined with file deletion. It completes in seconds, even for partitions with hundreds of millions of rows, and has minimal I/O, CPU, and memory overhead.If
ON TRUNCATEtriggers are defined on the table, this operation fires them. Ensure you understand the business logic of these triggers to prevent unintended side effects.
Examples
This example demonstrates how to truncate a historical quarterly partition from a sales records table. This is a common data lifecycle management task, where you delete old data but retain the partition structure to load new data for the same period later.
FAQ
Q1: What is the difference between TRUNCATE PARTITION and DROP PARTITION?TRUNCATE PARTITION removes only the data within a partition but retains the partition definition. In contrast, DROP PARTITION drops both the partition definition and all its data.
Q2: Can data be recovered after running TRUNCATE PARTITION?
No. TRUNCATE is a DDL operation that permanently deletes data. By default, it is not recorded in transaction logs and cannot be rolled back or recovered using standard flashback methods.
Q3: Why do I get the error RA-02149: specified partition does not exist when I run this command?
This error indicates that the specified partition does not exist or that its name has a case mismatch. Verify the exact partition name by running the query in the pre-check section, or use double quotation marks for an exact match.
Q4: Why do I get the error ORA-01031: insufficient privileges when I run this command?
This error occurs because the user running the command does not have the ALTER privilege on the target table. Contact your database administrator to grant the required privilege.
Q5: Why do I receive the error ERROR: cannot truncate partition of table because it has global indexes when I run this command?
TRUNCATE PARTITION fails if the table has global indexes. A global index maintains uniqueness and access paths across all partitions. The TRUNCATE operation cannot quickly clear index entries without compromising the integrity of the global index.
Related SQL statements
ALTER TABLE DROP PARTITION: Deletes a partition definition and its data.
ALTER TABLE ADD PARTITION: Adds a new partition to a partitioned table.
ALTER TABLE SPLIT PARTITION: Splits one partition into two new partitions.