search
HomeDatabaseOracleHow to add partitions to a table in oracle

In Oracle, you can use the ALTER statement with "ADD PARTITION" to add partitions to the table. The syntax is "ALTER TABLE table name ADD PARTITION partition VALUES".

How to add partitions to a table in oracle

The operating environment of this tutorial: Windows 10 system, Oracle 11g version, Dell G3 computer.

How to add a partition to the table in Oracle

1. Add a partition

The following command adds a P3 partition to the SALES table

ALTER TABLE SALES ADD PARTITION P3 VALUES LESS THAN(TO_DATE('2018-09-01','YYYY-MM-DD'));

Note: The partition boundary added above should be higher than the last partition boundary.

The following command adds a P3SUB1 subpartition to the P3 partition of the SALES table

ALTER TABLE SALES MODIFY PARTITION P3 ADD SUBPARTITION P3SUB1 VALUES('COMPLETE');

2. Delete the partition

The following command deletes the P3 table partition :

ALTER TABLE SALES DROP PARTITION P3;

The P4SUB1 subpartition was deleted with the following command:

ALTER TABLE SALES DROP SUBPARTITION P4SUB1;

Note: If the deleted partition is the only partition in the table, then this partition cannot be deleted. To delete this partition , the table must be deleted.

3. Truncate a partition

Truncating a partition means deleting the data in a partition. It will not delete the partition, nor will it delete the data in other partitions. data. When there is only one partition in the table, the partition can be truncated. Truncate a partition through the following command:

ALTER TABLE SALES TRUNCATE PARTITION P2;

Truncate a subpartition through the following command:

ALTER TABLE SALES TRUNCATE SUBPARTITION P2SUB2;

4. Merge partitions

Merge partitions to merge adjacent partitions Partitions are merged into one partition, and the resulting partition will take the boundaries of the higher partition. It is worth noting that partitions cannot be merged into a partition with lower boundaries. The following command realizes the merger of P1 and P2 partitions:

ALTER TABLE SALES MERGE PARTITIONS P1,P2 INTO PARTITION P2;

5. Split partition

Split partition Split one partition into two new partitions. After splitting The original partition no longer exists. Note that HASH type partitions cannot be split.

ALTER TABLE SALES SBLIT PARTITION P2 AT(TO_DATE('2003-02-01','YYYY-MM-DD')) INTO (PARTITION P21,PARTITION P22);

6. Joining partitions (coalesca)

Combining partitions is to join the data in the hash partition to other partitions. When the data in the hash partition is compared When it is large, you can add hash partitions and then join them. It is worth noting that join partitions can only be used in hash partitions. Use the following command to join the partition:

ALTER TABLE SALES COALESCA PARTITION;

7. Rename the table partition

The following command will change P21 to P2

ALTER TABLE SALES RENAME PARTITION P21 TO P2;

eight , Related queries

Cross-partition query

select sum( *) from
(select count(*) cn from t_table_SS PARTITION (P200709_1)
union all
select count(*) cn from t_table_SS PARTITION (P200709_2)
);

Query how many partitions there are on the table

SELECT * FROM USER_TAB_PARTITIONS WHERE TABLE_NAME='tableName'

Query index information

select object_name,object_type,tablespace_name,sum(value)
from v$segment_statistics
where statistic_name IN ('physical reads','physical write','logical reads')and object_type='INDEX'
group by object_name,object_type,tablespace_name
order by 4 desc
--显示数据库所有分区表的信息:
select * from DBA_PART_TABLES
--显示当前用户可访问的所有分区表信息:
select * from ALL_PART_TABLES
--显示当前用户所有分区表的信息:
select * from USER_PART_TABLES
--显示表分区信息 显示数据库所有分区表的详细分区信息:
select * from DBA_TAB_PARTITIONS
--显示当前用户可访问的所有分区表的详细分区信息:
select * from ALL_TAB_PARTITIONS
--显示当前用户所有分区表的详细分区信息:
select * from USER_TAB_PARTITIONS
--显示子分区信息 显示数据库所有组合分区表的子分区信息:
select * from DBA_TAB_SUBPARTITIONS
--显示当前用户可访问的所有组合分区表的子分区信息:
select * from ALL_TAB_SUBPARTITIONS
--显示当前用户所有组合分区表的子分区信息:
select * from USER_TAB_SUBPARTITIONS
--显示分区列 显示数据库所有分区表的分区列信息:
select * from DBA_PART_KEY_COLUMNS
--显示当前用户可访问的所有分区表的分区列信息:
select * from ALL_PART_KEY_COLUMNS
--显示当前用户所有分区表的分区列信息:
select * from USER_PART_KEY_COLUMNS
--显示子分区列 显示数据库所有分区表的子分区列信息:
select * from DBA_SUBPART_KEY_COLUMNS
--显示当前用户可访问的所有分区表的子分区列信息:
select * from ALL_SUBPART_KEY_COLUMNS
--显示当前用户所有分区表的子分区列信息:
select * from USER_SUBPART_KEY_COLUMNS
--怎样查询出oracle数据库中所有的的分区表
select * from user_tables a where a.partitioned='YES'
--删除一个表的数据是
truncate table table_name;
--删除分区表一个分区的数据是
alter table table_name truncate partition p5;

Recommended tutorial:《Oracle Video Tutorial

The above is the detailed content of How to add partitions to a table in oracle. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Oracle: Exploring the Company's Mission and ValueOracle: Exploring the Company's Mission and ValueApr 26, 2025 am 12:06 AM

Oracle's mission is to "help people see the value of data", and its core values ​​include: 1) Customer first, 2) Integrity, 3) Innovation, and 4) Teamwork. These values ​​guide Oracle's strategic decision-making and business innovation in the market.

Oracle's Core Function: Providing Database SolutionsOracle's Core Function: Providing Database SolutionsApr 25, 2025 am 12:06 AM

Oracle Database is a relational database management system that supports SQL and object relational models to provide data security and high availability. 1. The core functions of Oracle database include data storage, retrieval, security and backup and recovery. 2. Its working principle involves multi-layer storage structure, MVCC mechanism and optimizer. 3. Basic usages include creating tables, inserting and querying data; advanced usages involve stored procedures and triggers. 4. Performance optimization strategies include the use of indexes, optimized SQL statements and memory management.

Using Oracle Software: Database Management and BeyondUsing Oracle Software: Database Management and BeyondApr 24, 2025 am 12:18 AM

In addition to database management, Oracle software is also used in JavaEE applications, data grids and high-performance computing. 1. OracleWebLogicServer is used to deploy and manage JavaEE applications. 2. OracleCoherence provides high-performance data storage and caching services. 3. OracleExadata is used for high performance computing. These tools allow Oracle to play a more diversified role in the enterprise IT architecture.

Oracle's Role in the Business WorldOracle's Role in the Business WorldApr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Oracle Software in Action: Real-World ExamplesOracle Software in Action: Real-World ExamplesApr 22, 2025 am 12:12 AM

Oracle software applications in the real world include e-commerce platforms and manufacturing. 1) On e-commerce platforms, OracleDatabase is used to store and query user information. 2) In manufacturing, OracleE-BusinessSuite is used to optimize inventory and production planning.

Oracle Software: Applications and IndustriesOracle Software: Applications and IndustriesApr 21, 2025 am 12:01 AM

The reason why Oracle software shines in multiple fields is its powerful application and customized solutions. 1) Oracle provides comprehensive solutions from database management to ERP, CRM, SCM, 2) its solutions can be customized according to industry characteristics such as finance, medical care, manufacturing, etc. 3) Successful cases include Citibank, Mayo Clinic and Toyota, 4) The advantages lie in comprehensiveness, customization and scalability, but challenges include complexity, cost and integration issues.

Choosing Between MySQL and Oracle: A Decision GuideChoosing Between MySQL and Oracle: A Decision GuideApr 20, 2025 am 12:02 AM

Choosing MySQL or Oracle depends on project requirements: 1. MySQL is suitable for small and medium-sized applications and Internet projects because of its open source, free and ease of use; 2. Oracle is suitable for core business systems of large enterprises because of its powerful, stable and advanced functions, but at a high cost.

Oracle's Products: A Deep DiveOracle's Products: A Deep DiveApr 19, 2025 am 12:14 AM

Oracle's product ecosystem includes databases, middleware and cloud services. 1. OracleDatabase is its core product, supporting efficient data storage and management. 2. Middleware such as OracleWebLogicServer connects to different systems. 3. OracleCloud provides a complete set of cloud computing solutions.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.