1 删除无数据用分区(按照用户)
declare
cnt int;
p_name varchar2(50);
begin
for aa in (select t.partition_name,t.table_name
from dba_tab_partitions t
where t.table_owner in ('NCCMOLTP') and t.partition_name not like '%410927%') loop
begin
--select count(*) into cnt from tjfrecord partition(aa.partition_name);
execute immediate 'select count(*) from '||aa.table_name ||' partition('||aa.partition_name||')'
into cnt;
if cnt = 0 then
execute immediate 'alter table '||aa.table_name||' drop partition '||aa.partition_name;
end if;
end;
end loop;
end;
2 删除无数据子分区(按照用户)
declare
cnt int;
p_name varchar2(50);
begin
for aa in (select t.subpartition_name,t.table_name
from dba_tab_subpartitions t
where t.table_owner in ('NCCMHIST') and t.subpartition_name not like '%410927%') loop
begin
--select count(*) into cnt from tjfrecord partition(aa.partition_name);
execute immediate 'select count(*) from '||aa.table_name ||' subpartition('||aa.subpartition_name||')'
into cnt;
if cnt = 0 then
execute immediate 'alter table '||aa.table_name||' drop subpartition '||aa.subpartition_name;
end if;
end;
end loop;
end;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15747463/viewspace-751402/
,如需转载,请注明出处,否则将追究法律责任。