split命令分割分区的方法

发表于:2007-06-07来源:作者:点击数: 标签:
SQL select PARTITIONED from dba_tables where table_name='LYTUSAGE'; PAR --- YES SQL select PARTITION_NAME,HIGH_VALUE from dba_tab_partitions where TABLE_NAME='LYTUSAGE'; PARTITION_NAME HIGH_VALUE ------------------------------ ------------

SQL> select PARTITIONED from dba_tables where table_name='LYTUSAGE';

PAR
---
YES


SQL> select PARTITION_NAME,HIGH_VALUE from dba_tab_partitions where TABLE_NAME='LYTUSAGE';

PARTITION_NAME                 HIGH_VALUE
------------------------------ --------------------------------------------------------------------------------
LYTUSAGE_200401                TO_DATE(' 2004-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200402                TO_DATE(' 2004-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200403                TO_DATE(' 2004-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200404                TO_DATE(' 2004-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200405                TO_DATE(' 2004-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200406                TO_DATE(' 2004-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200407                TO_DATE(' 2004-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200408                TO_DATE(' 2004-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200409                TO_DATE(' 2004-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200410                TO_DATE(' 2004-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200411                TO_DATE(' 2004-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200412                TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200501                TO_DATE(' 2005-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200502                TO_DATE(' 2005-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200503                TO_DATE(' 2005-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200504                TO_DATE(' 2005-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200505                TO_DATE(' 2005-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200506                TO_DATE(' 2005-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200507                TO_DATE(' 2005-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200508                TO_DATE(' 2005-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200509                TO_DATE(' 2005-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200510                TO_DATE(' 2005-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200511                TO_DATE(' 2005-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200512                TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA

24 rows selected.

删除2005年1月和2月的分区:
SQL> alter table lytusage drop partition LYTUSAGE_200501;

Table altered.

SQL> alter table lytusage drop partition LYTUSAGE_200502;

Table altered.

SQL> select PARTITION_NAME,HIGH_VALUE,TABLESPACE_NAME from dba_tab_partitions where table_name='LYTUSAGE';

PARTITION_NAME                 HIGH_VALUE
------------------------------ --------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------

LYTUSAGE_200401                TO_DATE(' 2004-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200402                TO_DATE(' 2004-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200403                TO_DATE(' 2004-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200404                TO_DATE(' 2004-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200405                TO_DATE(' 2004-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200406                TO_DATE(' 2004-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200407                TO_DATE(' 2004-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200408                TO_DATE(' 2004-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200409                TO_DATE(' 2004-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200410                TO_DATE(' 2004-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200411                TO_DATE(' 2004-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200412                TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200503                TO_DATE(' 2005-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200504                TO_DATE(' 2005-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200505                TO_DATE(' 2005-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200506                TO_DATE(' 2005-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200507                TO_DATE(' 2005-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200508                TO_DATE(' 2005-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200509                TO_DATE(' 2005-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200510                TO_DATE(' 2005-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200511                TO_DATE(' 2005-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS

LYTUSAGE_200512                TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
WACOS


22 rows selected.


SQL> ALTER TABLE LYTUSAGE
SPLIT PARTITION LYTUSAGE_200503 AT (TO_DATE('2005-03-01 00:00:00','SYYYY-MM-DD HH24:MI:SS'))
INTO (partition LYTUSAGE_200502 tablespace wacos,partition LYTUSAGE_200503 tablespace wacos) UPDATE GLOBAL INDEXES;

Table altered.

SQL> ALTER TABLE LYTUSAGE
SPLIT PARTITION LYTUSAGE_200502 AT (TO_DATE('2005-02-01 00:00:00','SYYYY-MM-DD HH24:MI:SS'))
INTO (partition LYTUSAGE_200501 tablespace wacos,partition LYTUSAGE_200502 tablespace wacos) UPDATE GLOBAL INDEXES;

Table altered.

PARTITION_NAME                 HIGH_VALUE
------------------------------ --------------------------------------------------------------------------------
LYTUSAGE_200412                TO_DATE(' 2005-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200401                TO_DATE(' 2004-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200402                TO_DATE(' 2004-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200403                TO_DATE(' 2004-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200404                TO_DATE(' 2004-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200405                TO_DATE(' 2004-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200406                TO_DATE(' 2004-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200407                TO_DATE(' 2004-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200408                TO_DATE(' 2004-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200409                TO_DATE(' 2004-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200410                TO_DATE(' 2004-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200411                TO_DATE(' 2004-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200503                TO_DATE(' 2005-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200504                TO_DATE(' 2005-05-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200505                TO_DATE(' 2005-06-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200506                TO_DATE(' 2005-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200507                TO_DATE(' 2005-08-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200508                TO_DATE(' 2005-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200509                TO_DATE(' 2005-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200510                TO_DATE(' 2005-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200511                TO_DATE(' 2005-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200512                TO_DATE(' 2006-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200501                TO_DATE(' 2005-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
LYTUSAGE_200502                TO_DATE(' 2005-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA

24 rows selected.

SQL> alter table lytusage drop partition LYTUSAGE_200511;

Table altered.

SQL> alter table lytusage drop partition LYTUSAGE_200512;

Table altered.

SQL> ALTER TABLE LYTUSAGE ADD PARTITION LYTUSAGE_200511
VALUES LESS THAN (TO_DATE('2005-12-01 00:00:00','SYYYY-MM-DD HH24:MI:SS'))
TABLESPACE wacos 
STORAGE(
 INITIAL 1M
 NEXT 10M
 MINEXTENTS 1
 MAXEXTENTS unlimited
 PCTINCREASE 0 )
 PCTFREE 5
 PCTUSED 95
 NOLOGGING;

Table altered.

ALTER TABLE LYTUSAGE ADD PARTITION LYTUSAGE_200512
VALUES LESS THAN (TO_DATE('2006-01-01 00:00:00','SYYYY-MM-DD HH24:MI:SS'))
TABLESPACE wacos 
STORAGE(
 INITIAL 1M
 NEXT 10M
 MINEXTENTS 1
 MAXEXTENTS unlimited
 PCTINCREASE 0 )
 PCTFREE 5
 PCTUSED 95
 NOLOGGING;

Table altered.


原文转自:http://www.ltesting.net