ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ORACLE 删除无用分区

ORACLE 删除无用分区

原创 Linux操作系统 作者:renjixinchina 时间:2012-12-20 10:47:51 0 删除 编辑
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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-01-30

  • 博文量
    373
  • 访问量
    2161066