马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
用一个库#bak_database存放这些历史数据。
SQL>selectPARTITIONEDfromdba_tableswheretable_name=LYTUSAGE;
PAR
---
YES
SQL>selectPARTITION_NAME,HIGH_VALUEfromdba_tab_partitionswhereTABLE_NAME=LYTUSAGE;
PARTITION_NAMEHIGH_VALUE
--------------------------------------------------------------------------------------------------------------
LYTUSAGE_200401TO_DATE(2004-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200402TO_DATE(2004-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200403TO_DATE(2004-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200404TO_DATE(2004-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200405TO_DATE(2004-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200406TO_DATE(2004-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200407TO_DATE(2004-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200408TO_DATE(2004-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200409TO_DATE(2004-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200410TO_DATE(2004-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200411TO_DATE(2004-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200412TO_DATE(2005-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200501TO_DATE(2005-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200502TO_DATE(2005-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200503TO_DATE(2005-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200504TO_DATE(2005-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200505TO_DATE(2005-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200506TO_DATE(2005-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200507TO_DATE(2005-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200508TO_DATE(2005-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200509TO_DATE(2005-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200510TO_DATE(2005-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200511TO_DATE(2005-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200512TO_DATE(2006-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
24rowsselected.
删除2005年1月和2月的分区:
SQL>altertablelytusagedroppartitionLYTUSAGE_200501;
Tablealtered.
SQL>altertablelytusagedroppartitionLYTUSAGE_200502;
Tablealtered.
SQL>selectPARTITION_NAME,HIGH_VALUE,TABLESPACE_NAMEfromdba_tab_partitionswheretable_name=LYTUSAGE;
PARTITION_NAMEHIGH_VALUE
--------------------------------------------------------------------------------------------------------------
TABLESPACE_NAME
------------------------------
LYTUSAGE_200401TO_DATE(2004-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200402TO_DATE(2004-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200403TO_DATE(2004-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200404TO_DATE(2004-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200405TO_DATE(2004-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200406TO_DATE(2004-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200407TO_DATE(2004-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200408TO_DATE(2004-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200409TO_DATE(2004-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200410TO_DATE(2004-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200411TO_DATE(2004-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200412TO_DATE(2005-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200503TO_DATE(2005-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200504TO_DATE(2005-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200505TO_DATE(2005-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200506TO_DATE(2005-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200507TO_DATE(2005-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200508TO_DATE(2005-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200509TO_DATE(2005-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200510TO_DATE(2005-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200511TO_DATE(2005-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
LYTUSAGE_200512TO_DATE(2006-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
WACOS
22rowsselected.
SQL>ALTERTABLELYTUSAGE
SPLITPARTITIONLYTUSAGE_200503AT(TO_DATE(2005-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS))
INTO(partitionLYTUSAGE_200502tablespacewacos,partitionLYTUSAGE_200503tablespacewacos)UPDATEGLOBALINDEXES;
Tablealtered.
SQL>ALTERTABLELYTUSAGE
SPLITPARTITIONLYTUSAGE_200502AT(TO_DATE(2005-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS))
INTO(partitionLYTUSAGE_200501tablespacewacos,partitionLYTUSAGE_200502tablespacewacos)UPDATEGLOBALINDEXES;
Tablealtered.
PARTITION_NAMEHIGH_VALUE
--------------------------------------------------------------------------------------------------------------
LYTUSAGE_200412TO_DATE(2005-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200401TO_DATE(2004-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200402TO_DATE(2004-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200403TO_DATE(2004-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200404TO_DATE(2004-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200405TO_DATE(2004-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200406TO_DATE(2004-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200407TO_DATE(2004-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200408TO_DATE(2004-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200409TO_DATE(2004-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200410TO_DATE(2004-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200411TO_DATE(2004-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200503TO_DATE(2005-04-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200504TO_DATE(2005-05-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200505TO_DATE(2005-06-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200506TO_DATE(2005-07-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200507TO_DATE(2005-08-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200508TO_DATE(2005-09-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200509TO_DATE(2005-10-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200510TO_DATE(2005-11-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200511TO_DATE(2005-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200512TO_DATE(2006-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200501TO_DATE(2005-02-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
LYTUSAGE_200502TO_DATE(2005-03-0100:00:00,SYYYY-MM-DDHH24:MI:SS,NLS_CALENDAR=GREGORIA
24rowsselected.
SQL>altertablelytusagedroppartitionLYTUSAGE_200511;
Tablealtered.
SQL>altertablelytusagedroppartitionLYTUSAGE_200512;
Tablealtered.
SQL>ALTERTABLELYTUSAGEADDPARTITIONLYTUSAGE_200511
VALUESLESSTHAN(TO_DATE(2005-12-0100:00:00,SYYYY-MM-DDHH24:MI:SS))
TABLESPACEwacos
STORAGE(
INITIAL1M
NEXT10M
MINEXTENTS1
MAXEXTENTSunlimited
PCTINCREASE0)
PCTFREE5
PCTUSED95
NOLOGGING;
Tablealtered.
ALTERTABLELYTUSAGEADDPARTITIONLYTUSAGE_200512
VALUESLESSTHAN(TO_DATE(2006-01-0100:00:00,SYYYY-MM-DDHH24:MI:SS))
TABLESPACEwacos
STORAGE(
INITIAL1M
NEXT10M
MINEXTENTS1
MAXEXTENTSunlimited
PCTINCREASE0)
PCTFREE5
PCTUSED95
NOLOGGING;
Tablealtered.
优化的SQL查询算法,有效地提高查询速度 |