OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Database

SQL - V4.2.1

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    Company
    About OceanBaseTrust CenterLegalPartnerContact Us
    Follow Us

    © OceanBase 2026. All rights reserved

    Cloud Service AgreementPrivacy PolicySecurity
    Contact Us
    Document Feedback
    1. Documentation Center
    2. OceanBase Database
    3. SQL
    4. V4.2.1
    iconOceanBase Database
    SQL - V 4.2.1
    SQL
    KV
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Truncate a partition

    Last Updated:2023-12-25 08:49:41  Updated
    share
    What is on this page
    Support for truncating a partition from a partitioned table
    Considerations
    Truncate a partition
    Syntax
    Examples
    Truncate a subpartition
    Syntax
    Example

    folded

    share

    You can clear the data in a partition of a partitioned table but retain the partition structure.

    Support for truncating a partition from a partitioned table

    Take note of the following points in the Oracle mode of OceanBase Database:

    • You can truncate partitions only for RANGE- and LIST-partitioned tables. You cannot truncate partitions for HASH partitioned tables.

    • In the case of subpartitioned tables, you can truncate partitions only for RANGE-LIST partitioned tables.

    The following table describes the support for truncating partitions from partitioned and subpartitioned tables in the Oracle mode of OceanBase Database.

    Partitioned table Partitioning type Truncate a partition Truncate a subpartition
    Partitioned table RANGE and LIST Supported -
    Partitioned table HASH Not supported -
    Subpartitioned table RANGE-RANGE and RANGE-LIST Supported Supported
    Subpartitioned table RANGE-HASH Not supported Not supported
    Subpartitioned table LIST-RANGE and LIST-LIST Supported Supported
    Subpartitioned table LIST-HASH Not supported Not supported
    Subpartitioned table HASH-RANGE, HASH-LIST, and HASH-HASH Not supported Not supported

    Considerations

    Before you truncate a partition, note that:

    • Before you truncate a partition, ensure that no active transactions or queries exist in this partition. Otherwise, SQL statement errors or exceptions may occur. You can query the oceanbase.GV$OB_TRANSACTION_PARTICIPANTS view for the context status of unfinished transactions in the sys tenant.

    • In the Oracle mode of OceanBase Database, when you truncate a partition from a partitioned or subpartitioned table with global indexes, you must add the UPDATE GLOBAL INDEXES keyword to the ALTER TABLE statement to update global indexes. If the UPDATE GLOBAL INDEXES keyword is not added, the global indexes of this partitioned table become unavailable after the partition is truncated.

    Truncate a partition

    You can truncate a partition from a partitioned or subpartitioned table as needed.

    Syntax

    ALTER TABLE table_name TRUNCATE PARTITION partition_name_list [UPDATE GLOBAL INDEXES];
    
    partition_name_list:
      partition_name [, partition_name ...]
    

    Note

    • You can clear the data in one or more partitions by using the TRUNCATE statement.

    • When you truncate a partition from a subpartitioned table, all data in this partition and its subpartitions is cleared.

    Examples

    • Clear the data in the M202001 and M202002 partitions of the tbl1_r partitioned table, and update the global indexes.

      obclient> CREATE TABLE tbl1_r(log_id INT,log_date DATE NOT NULL DEFAULT SYSDATE)
             PARTITION BY RANGE(log_date)
              (PARTITION M202001 VALUES LESS THAN(TO_DATE('2020/02/01','YYYY/MM/DD'))
               , PARTITION M202002 VALUES LESS THAN(TO_DATE('2020/03/01','YYYY/MM/DD'))
               , PARTITION M202003 VALUES LESS THAN(TO_DATE('2020/04/01','YYYY/MM/DD'))
               , PARTITION M202004 VALUES LESS THAN(TO_DATE('2020/05/01','YYYY/MM/DD'))
               , PARTITION M202005 VALUES LESS THAN(TO_DATE('2020/06/01','YYYY/MM/DD'))
               , PARTITION M202006 VALUES LESS THAN(TO_DATE('2020/07/01','YYYY/MM/DD'))
               , PARTITION M202007 VALUES LESS THAN(TO_DATE('2020/08/01','YYYY/MM/DD'))
               , PARTITION M202008 VALUES LESS THAN(TO_DATE('2020/09/01','YYYY/MM/DD'))
               , PARTITION M202009 VALUES LESS THAN(TO_DATE('2020/10/01','YYYY/MM/DD'))
               , PARTITION M202010 VALUES LESS THAN(TO_DATE('2020/11/01','YYYY/MM/DD'))
               , PARTITION M202011 VALUES LESS THAN(TO_DATE('2020/12/01','YYYY/MM/DD'))
               , PARTITION M202012 VALUES LESS THAN(TO_DATE('2021/01/01','YYYY/MM/DD'))
               , PARTITION MMAX VALUES LESS THAN (MAXVALUE)
               );
      Query OK, 0 rows affected
      
      obclient> ALTER TABLE tbl1_r TRUNCATE PARTITION M202001,M202002 UPDATE GLOBAL INDEXES;
      Query OK, 0 rows affected
      
    • Truncate the p0 and p1 partitions of the RANGE-LIST-subpartitioned table t2_f_rl.

      obclient> ALTER TABLE t2_f_rl TRUNCATE PARTITION p0,p1;
      

    Truncate a subpartition

    You can truncate a partition from a subpartitioned table as needed.

    Syntax

    ALTER TABLE table_name TRUNCATE SUBPARTITION subpartition_name_list[ UPDATE GLOBAL INDEXES ];
    
    subpartition_name_list:
      subpartition_name[, subpartition_name ...]
    

    Note

    You can clear the data in one or more subpartitions by using the TRUNCATE statement.

    Example

    Truncate the sp3 and sp4 subpartitions from the p1 partition of the t2_f_lr subpartitioned table, and then update the global indexes.

    obclient> CREATE TABLE t2_f_rl(col1 INT,col2 VARCHAR2(50))
           PARTITION BY RANGE(col1)
           SUBPARTITION BY LIST(col2)
           (PARTITION p0 VALUES LESS THAN(100)
             (SUBPARTITION sp0 VALUES('01'),
              SUBPARTITION sp1 VALUES('02')
              ),
            PARTITION p1 VALUES LESS THAN(200)
             (SUBPARTITION sp2 VALUES('01'),
              SUBPARTITION sp3 VALUES('02'),
              SUBPARTITION sp4 VALUES('03')
             )
            );
    Query OK, 0 rows affected
    
    obclient> ALTER TABLE t2_f_lr TRUNCATE SUBPARTITION sp3,sp4 UPDATE GLOBAL INDEXES;
    Query OK, 0 rows affected
    

    Previous topic

    Drop a partition
    Last

    Next topic

    Partition pruning
    Next
    What is on this page
    Support for truncating a partition from a partitioned table
    Considerations
    Truncate a partition
    Syntax
    Examples
    Truncate a subpartition
    Syntax
    Example