Oracle 常见初始化参数

使用间隔分区的场景:

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.

注意,合并的两个分区需要前后相连,否则报错,无法合并!

猜你喜欢

转载自www.linuxidc.com/Linux/2015-08/121637.htm
今日推荐