How 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".
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

Deleting all data in Oracle requires the following steps: 1. Establish a connection; 2. Disable foreign key constraints; 3. Delete table data; 4. Submit transactions; 5. Enable foreign key constraints (optional). Be sure to back up the database before execution to prevent data loss.

Oracle database paging uses ROWNUM pseudo-columns or FETCH statements to implement: ROWNUM pseudo-columns are used to filter results by row numbers and are suitable for complex queries. The FETCH statement is used to get the specified number of first rows and is suitable for simple queries.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node
