Partitions are automatically created under Oracle11g

Source: Internet
Author: User

Before 11g, You need to manually maintain the partition. After 11 GB, interval is used to implement automatic expansion of partitions, which simplifies maintenance.

By YEAR: INTERVAL (NUMTOYMINTERVAL (1, 'Year '))

By MONTH: INTERVAL (NUMTOYMINTERVAL (1, 'month '))

By DAY: INTERVAL (NUMTODSINTERVAL (1, 'day '))

By time, MINUTE, and SECOND: NUMTODSINTERVAL (n, {'day' | 'hour' | 'minute '| 'second '})

The following is an experiment with monthly auto Scaling:

SQL> create table t_range (id number not null PRIMARY KEY, test_date date)
Partition by range (test_date) interval (numtoyMinterval (1, 'month '))
(
Partition p_2014_01_01 values less than (to_date ('2017-01-01 ', 'yyyy-mm-dd '))
);
-- Only one partition is displayed.
SQL> select partition_name from user_tab_partitions where table_name = 't_ range ';
PARTITION_NAME
------------------------------
P_2014_01_01


SQL> insert/* + append */into t_range select rownum,
To_date (to_char (sysdate-140, 'J') +
Trunc (dbms_random.value (0, 80 )),
'J ')
From dual
Connect by rownum <= 100000;
SQL> commit;

-- The partitions starting with SYS are automatically extended.
SQL> select partition_name from user_tab_partitions where table_name = 't_ range ';
PARTITION_NAME
------------------------------
P_2014_01_01
Sys_p21.
SYS_P22
SYS_P23

-- Let's look at the t_range table structure.

Create table T_RANGE
(
Id number not null,
TEST_DATE DATE
)
Partition by range (TEST_DATE)
(
Partition P_2014_01_01 values less than (TO_DATE ('00:00:00 ',
'Syyyy-MM-DD HH24: MI: ss', 'nls _ CALENDAR = GREGORIAN ')),
Partition sys_p2values less than (TO_DATE ('00:00:00 ',
'Syyyy-MM-DD HH24: MI: ss', 'nls _ CALENDAR = GREGORIAN ')),
Partition SYS_P22 values less than (TO_DATE ('00:00:00 ',
'Syyyy-MM-DD HH24: MI: ss', 'nls _ CALENDAR = GREGORIAN ')),
Partition SYS_P23 values less than (TO_DATE ('00:00:00 ',
'Syyyy-MM-DD HH24: MI: ss', 'nls _ CALENDAR = GREGORIAN '))
);
-- Create/Recreate primary, unique and foreign key constraints
Alter table T_RANGE
Add primary key (ID );

-- If the partition name is not very good, you can modify it yourself:

Alter table t_range rename partition sys_p2 to p_2014_02_01;
Alter table t_range rename partition SYS_P22 to p_2014_03_01;
Alter table t_range rename partition SYS_P23 to p_2014_04_01;

From official documents:

Restrictions on Interval Partitioning The INTERVAL clause is subject to the restrictions listed in "Restrictions on Partitioning in General" and "Restrictions on Range Partitioning". The following additional restrictions apply:

You can specify only one partitioning key column, and it must be of NUMBER, DATE, FLOAT, or TIMESTAMP data type.

This clause is not supported for index-organized tables.

This clause is not supported for tables containing nested table columns or varray columns.

You cannot create a domain index on an interval-partitioned table.

Interval partitioning is not supported at the subpartition level.

Serializable transactions do not work with interval partitioning. Trying to insert data into a partition of an interval partitioned table that does not yet have a segment causes an error.

In the VALUES clause:

You cannot specify MAXVALUE (an infinite upper bound), because doing so wocould defeat the purpose of the automatic addition of partitions as needed.

You cannot specify NULL values for the partitioning key column.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.