您的位置:首页 > 数据库 > Oracle

ORACLE基础操作【01】 -->MOVE 分区表

2015-05-04 22:52 761 查看
SQL> select * from v$version;

BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

--不含有子分区的分区表操作
SQL> create table pt1(
  2  object_id number,
  3  status varchar2(8)
  4  )
  5  partition by range(object_id)
  6  (
  7  partition p01 values  less than (10000),
  8  partition p02 values less than (20000),
  9  partition p03 values less than (30000),
 10  partition pmax values less than (maxvalue)
 11  );

Table created.

SQL> insert into pt1
  2  select object_id,status from dba_objects;

71937 rows created.

SQL> commit;

Commit complete.

--创建分区索引
SQL> create index idx_pt1 on pt1(object_id) local;

Index created.

SQL> select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where index_owner='AIKI'
  2  
SQL> .
SQL> /

INDEX_NAME                     PARTITION_NAME                 STATUS
------------------------------ ------------------------------ --------
IDX_PT1                        PMAX                           USABLE
IDX_PT1                        P03                            USABLE
IDX_PT1                        P02                            USABLE
IDX_PT1                        P01                            USABLE

SQL> alter table pt1 move partition p01 tablespace tartbs;

Table altered.

INDEX_NAME                     PARTITION_NAME                 STATUS
------------------------------ ------------------------------ --------
IDX_PT1                        PMAX                           USABLE
IDX_PT1                        P03                            USABLE
IDX_PT1                        P02                            USABLE
IDX_PT1                        P01                            UNUSABLE

SQL> alter table pt1 move partition p01 tablespace tartbs update indexes;

Table altered.

  1* select INDEX_NAME,PARTITION_NAME,STATUS from dba_ind_partitions where index_owner='AIKI'
SQL> /

INDEX_NAME                     PARTITION_NAME                 STATUS
------------------------------ ------------------------------ --------
IDX_PT1                        PMAX                           USABLE
IDX_PT1                        P03                            USABLE
IDX_PT1                        P02                            USABLE
IDX_PT1                        P01                            USABLE

SQL> alter table pt1 move partition p01 tablespace tartbs nologging compress update indexes;

Table altered.

SQL> alter table pt1 move partition p01 tablespace tartbs nologging compress update indexes parallel 4;

Table altered.

SQL> drop index idx_pt1;

Index dropped.

Elapsed: 00:00:00.06
SQL> 
SQL> create index idx_pt1 on pt1(object_id);

Index created.

Elapsed: 00:00:00.08
SQL> alter table pt1 move partition p01 tablespace tartbs;

Table altered.

Elapsed: 00:00:00.05

INDEX_NAME                     DEGREE                                   STATUS
------------------------------ ---------------------------------------- --------
IDX_PT1                        1                                        UNUSABLE

SQL> alter table pt1 move partition p01 tablespace tartbs update indexes;

Table altered.

INDEX_NAME                     DEGREE                                   STATUS
------------------------------ ---------------------------------------- --------
IDX_PT1                        1                                        UNUSABLE

SQL> alter table pt1 move partition p01 tablespace tartbs update  global indexes;

Table altered.

INDEX_NAME                     DEGREE                                   STATUS
------------------------------ ---------------------------------------- --------
IDX_PT1                        1                                        UNUSABLE

--可以在move table后再单独的rebuild index
SQL> ALTER INDEX idx_pt1  REBUILD tablespace tartbs;

Index altered.

INDEX_NAME                     DEGREE                                   STATUS
------------------------------ ---------------------------------------- --------
IDX_PT1                        1                                        VALID

--对于分区表的语法为:
SQL> alter index idx_pt1 rebuild partition p02  tablespace tartbs parallel 4;

Index altered.

SQL> drop table pt1 purge;

Table dropped.

--move含有子分区的表

SQL> create table subpt1(
  2  object_id number,
  3  status varchar2(8)
  4  )
  5  partition by range(object_id)
  6  subpartition by list(status)
  7  (
  8  partition pt1 values less than(10000)
  9  (
 10  subpartition subpt1 values('VALID'),
 11  subpartition subpt2 values('INVALID')
 12  ),
 13  partition pt2 values less than(20000)
 14  (
 15  subpartition subpt3 values('VALID'),
 16  subpartition subpt4 values('INVALID')
 17  ),
 18  partition pt3 values less than(30000)
 19  (
 20  subpartition subpt5 values('VALID'),
 21  subpartition subpt6 values('INVALID')
 22  ),
 23  partition pmax values less than(maxvalue)
 24  (
 25  subpartition subpt7 values('VALID'),
 26  subpartition subpt8 values('INVALID')
 27  )
 28  );

Table created.

SQL> insert into subpt1 select object_id,status from dba_objects;

71931 rows created.

SQL> commit;

Commit complete.

SQL> update subpt1 set status='INVALID' where object_id between 0 and 10000 and rownum<100;
update subpt1 set status='INVALID' where object_id between 0 and 10000 and rownum<100
       *
ERROR at line 1:
ORA-14402: updating partition key column would cause a partition change

SQL> alter table subpt1 enable row movement;

Table altered.

SQL> update subpt1 set status='INVALID' where object_id between 0 and 10000 and rownum<100;

99 rows updated.

SQL> update subpt1 set status='INVALID' where object_id between 10000 and 20000 and rownum<100;

99 rows updated.

SQL> update subpt1 set status='INVALID' where object_id between 20000 and 30000 and rownum<100;

99 rows updated.

Index created.

PARTITION_NAME                 SUBPARTITION_NAME              STATUS
------------------------------ ------------------------------ --------
PT1                            SUBPT1                         USABLE
PT1                            SUBPT2                         USABLE
PT2                            SUBPT3                         USABLE
PT2                            SUBPT4                         USABLE
PT3                            SUBPT5                         USABLE
PT3                            SUBPT6                         USABLE
PMAX                           SUBPT7                         USABLE
PMAX                           SUBPT8                         USABLE

SQL> alter table subpt1 move subpartition subpt2  tablespace tartbs;

Table altered.

PARTITION_NAME                 SUBPARTITION_NAME              STATUS
------------------------------ ------------------------------ --------
PT1                            SUBPT1                         USABLE
PT1                            SUBPT2                         UNUSABLE
PT2                            SUBPT3                         USABLE
PT2                            SUBPT4                         USABLE
PT3                            SUBPT5                         USABLE
PT3                            SUBPT6                         USABLE
PMAX                           SUBPT7                         USABLE
PMAX                           SUBPT8                         USABLE

SQL> alter index idx_subpt1 rebuild subpartition subpt2 tablespace tartbs;

Index altered.

PARTITION_NAME                 SUBPARTITION_NAME              STATUS
------------------------------ ------------------------------ --------
PT1                            SUBPT1                         USABLE
PT1                            SUBPT2                         USABLE
PT2                            SUBPT3                         USABLE
PT2                            SUBPT4                         USABLE
PT3                            SUBPT5                         USABLE
PT3                            SUBPT6                         USABLE
PMAX                           SUBPT7                         USABLE
PMAX                           SUBPT8                         USABLE

SQL> alter table subpt1 move subpartition subpt2  tablespace tartbs compress;

Table altered.

SQL> alter table subpt1 move subpartition subpt2  tablespace tartbs nologging compress;
alter table subpt1 move subpartition subpt2  tablespace tartbs nologging compress
                                                               *
ERROR at line 1:
ORA-14160: this physical attribute may not be specified for a table
subpartition

详情参见:8-39(p641)<sql language>
NOLOGGING is supported in only a subset of the locations that support LOGGING. Only
the following operations support the NOLOGGING mode:

SQL> alter index idx_subpt1 rebuild subpartition subpt2 tablespace tartbs;

Index altered.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: