-
测试表
-
CREATE TABLE "TEST"."TMP_PART_DAY2"
-
( "ID" NUMBER(20,0) NOT NULL ENABLE,
-
"NAME" VARCHAR2(1000),
-
"MEMO" VARCHAR2(1000),
-
"CREATE_TIME" DATE
-
) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
-
STORAGE(
-
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
-
TABLESPACE "USERS"
-
PARTITION BY RANGE ("CREATE_TIME") INTERVAL (NUMTODSINTERVAL(1, 'DAY'))
-
(PARTITION "SYS_P928" VALUES LESS THAN (TO_DATE(' 2021-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) SEGMENT CREATION IMMEDIATE
-
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
-
NOCOMPRESS LOGGING
-
STORAGE(INITIAL 8388608 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
-
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
-
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
-
TABLESPACE "USERS" );
-
-
插入几条数据:
-
insert into TMP_PART_DAY2 values(1,'aaa','bbb',sysdate -100);
-
insert into TMP_PART_DAY2 values(1,'aaa','bbb',sysdate -90);
-
insert into TMP_PART_DAY2 values(1,'aaa','bbb',sysdate -88);
-
insert into TMP_PART_DAY2 values(1,'aaa','bbb',sysdate -12);
-
commit;
-
-
找原因,看表定义
-
set long 1000
-
SELECT DBMS_METADATA.GET_DDL ('TABLE','TMP_PART_DAY2','TEST') FROM DUAL;
-
-
找规律,准备清理
-
col table_name for a20
-
col PARTITION_NAME for a20
-
col HIGH_VALUE for a55
-
select TABLE_NAME,PARTITION_NAME,HIGH_VALUE,PARTITION_POSITION,TABLESPACE_NAME,NUM_ROWS from DBA_tab_partitions where TABLE_NAME='TMP_PART_DAY2';
-
-
拼脚本,然后执行
-
select 'alter table test.TMP_PART_DAY2 drop partition '||partition_name||' update indexes; ' c
-
from dba_segments where segment_name='TMP_PART_DAY2' and PARTITION_NAME<='SYS_P950';
然后即可执行生成的脚本,对不想要的分区清理,如果PARTITION_NAME比较乱,没有规律,那么PARTITION_POSITION条件也可以考虑(and partition_position<900)。
阅读(1255) | 评论(0) | 转发(0) |