间隔分区是范围分区的一个拓展,当插入的数据超过了现有的所有分区时,数据库会按照指定的间隔自动创建分区。Oracle支持创建单一
间隔分区是范围分区的一个拓展,当插入的数据超过了现有的所有分区时,数据库会按照指定的间隔自动创建分区。Oracle支持创建单一的间隔分区表也可以创建interval-range、interval-hash和interval-list三种组合分区表。
使用间隔分区的场景:
1.使用间隔分区最大的好处就是不用再提前手工的创建分区,只要后续创建的分区的分区间隔是统一的,就可以考虑使用间隔分区。并且,在后续创建的分区中还能通过store in 选项以循环复用的方式来将分区存放到不同的表空间里。
2.如果某张表是范围分区,则很容易的将该表转换成间隔分区表,例如sh用户下的sales表,可通过如下语句来修改:
SH@ORA11GR2 > ALTER TABLE sales SET INTERVAL (NUMTOYMINTERVAL(1,'MONTH'));
Table altered.
注意,如果范围分区存在最大分区MAXVALUE时,无法通过命令直接改为间隔分区。
例如,先创建表interval_test
create table interval_test (id number, name varchar2(20))
partition by range(id)
(partition p1 values less than (100),
partition p2 values less than (200),
partition p3 values less than(MAXVALUE));
接着尝试将该表修改为间隔分区表
SH@ORA11GR2 > alter table interval_test set interval (200);
alter table interval_test set interval (200)
*
ERROR at line 1:
ORA-14759: SET INTERVAL is not legal on this table.
使用oerr查看报错信息
[oracle@oracle11g ~]$ oerr ora 14759
14759, 00000, "SET INTERVAL is not legal on this table."
// *Cause: SET INTERVAL clause was specified. ALTER TABLE SET INTERVAL is
// only legal on a range partitioned table with a single partitioning
// column. Additionally, this table cannot have a maxvalue partition
// and cannot be the parent table for any reference partitioned tables.
// *Action: Use SET INTERVAL only on a valid table.
3.如果某张表为间隔分区表,则无法手工的对该表手动新增分区。所以如果决定将某张表修改为间隔分区,要考虑修改相关的应用程序或者存储过程。
SH@ORA11GR2 > alter table interval_sales add partition p4 values less than (to_date('20150101','yyyymmdd'));
alter table interval_sales add partition p4 values less than (to_date('20150101','yyyymmdd'))
*
ERROR at line 1:
ORA-14760: ADD PARTITION is not permitted on Interval partitioned objects
使用间隔分区的限制:
1.只能指定一个分区键,,并且键值类型只能为number或date。
2.间隔分区不支持索引组织表。
3.不能在间隔分区上创建域索引(domain index)
管理间隔分区:
1.创建间隔分区:
CREATE TABLE interval_sales
( prod_id NUMBER(6)
, cust_id NUMBER
, time_id DATE
, channel_id CHAR(1)
, promo_id NUMBER(6)
, quantity_sold NUMBER(3)
, amount_sold NUMBER(10,2)
)
PARTITION BY RANGE (time_id)
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
STORE IN (interv1, interv2)
( PARTITION p0 VALUES LESS THAN (TO_DATE('1-1-2008', 'DD-MM-YYYY')),
PARTITION p1 VALUES LESS THAN (TO_DATE('1-1-2009', 'DD-MM-YYYY')),
PARTITION p2 VALUES LESS THAN (TO_DATE('1-7-2009', 'DD-MM-YYYY')),
PARTITION p3 VALUES LESS THAN (TO_DATE('1-1-2010', 'DD-MM-YYYY')) );
2.禁用间隔分区
SH@ORA11GR2 > alter table interval_sales set interval ();
Table altered.
3.修改间隔分区interval值
SH@ORA11GR2 > alter table interval_sales set interval (NUMTOYMINTERVAL(1,'YEAR'));
Table altered.
4.删除间隔分区
SH@ORA11GR2 > ALTER TABLE interval_sales DROP PARTITION FOR(TO_DATE(' 2008-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
Table altered.
5.Merge间隔分区
首先插入两条数据,让系统自动生成两个间隔分区
SH@ORA11GR2 > insert into interval_sales values (1,2,to_date('20150101','yyyymmdd'),3,3,3,3);
1 row created.
SH@ORA11GR2 > commit;
Commit complete.
SH@ORA11GR2 > insert into interval_sales values (1,2,to_date('20150201','yyyymmdd'),3,3,3,3);
1 row created.
SH@ORA11GR2 > commit;
接着,执行命令,合并两个分区
SH@ORA11GR2 > alter table interval_sales merge partitions for ( to_date('20150101','yyyymmdd')) , for(to_date('20150201','yyyymmdd'));
Table altered.
注意,合并的两个分区需要前后相连,否则报错,无法合并!
本文永久更新链接地址:

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


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

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.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools