选出有行连接(row chain)或者是行迁移(row migeration)的表

自己编写的一个小脚本,该脚本的主要功能是选出有行迁移或者行连接的表,并且按照行迁移/行连接降序输出OWNER.TABLE_NAME,该脚本没有统计ORACLE系统内置的表,如果表的索引状态为unusable,也不能统计,请在数据库空闲的时候运行该脚本。
 严重警告:请别在生产环境中乱用该脚本,后果自负
set serveroutput on
set linesize 200
set pagesize 100
declare
TYPE tablename IS RECORD 
( owner dba_tables.owner%TYPE,
  table_name dba_tables.table_name%TYPE,
  chain_cnt dba_tables.chain_cnt%TYPE
);
dbatables tablename;
cursor table_name is
select owner,table_name from dba_tables where owner not in
('SYS','SYSMAN','SYSTEM','MDSYS','OLAPSYS','DMSYS','ORDSYS','EXFSYS','XDB','CTXSYS','WMSYS','OUTLN','ISMSYS','DBSNMP','TSMSYS') and owner not in (select owner from dba_indexes where status='UNUSABLE');
cursor table_name2 is
select owner,table_name,chain_cnt from dba_tables where owner not in 
('SYS','SYSMAN','SYSTEM','MDSYS','OLAPSYS','DMSYS','ORDSYS','EXFSYS','XDB','CTXSYS','WMSYS','OUTLN','ISMSYS','DBSNMP','TSMSYS')
and chain_cnt>0 order by chain_cnt desc;
cursor spetial is select owner,table_name from dba_indexes where status='UNUSABLE';
begin 
  for tablename in table_name loop
execute immediate 'analyze table '|| tablename.owner ||'.'||tablename.table_name || ' compute statistics ';
end loop;
  for c_spetial in spetial loop 
dbms_output.put_line('UNUSABLE index in ' || c_spetial.owner ||'.' ||c_spetial.table_name || ' , Can not analyze this table');
end loop;
open table_name2;
loop
fetch table_name2 into dbatables;
if(table_name2%ROWCOUNT=0) then
dbms_output.put_line('No Chained Rows Found !!!');
else
dbms_output.put_line(dbatables.chain_cnt || ' chained rows found in ' ||  dbatables.owner ||'.'|| dbatables.table_name);
end if;
exit when table_name2%NOTFOUND;
end loop;
end;
/

例子:

SQL> set serveroutput on
SQL> set linesize 200
SQL> set pagesize 100
SQL> declare
  2  TYPE tablename IS RECORD
  3  ( owner dba_tables.owner%TYPE,
  4    table_name dba_tables.table_name%TYPE,
  5    chain_cnt dba_tables.chain_cnt%TYPE
  6  );
  7  dbatables tablename;
  8  cursor table_name is
  9  select owner,table_name from dba_tables where owner not in
 10  ('SYS','SYSMAN','SYSTEM','MDSYS','OLAPSYS','DMSYS','ORDSYS','EXFSYS','XDB','CTXSYS','WMSYS','OUTLN','ISMSYS','DBSNMP','TSMSYS') and owner not in (select owner from dba_indexes where status='UNUSA
BLE');
 11  cursor table_name2 is
 12  select owner,table_name,chain_cnt from dba_tables where owner not in
 13  ('SYS','SYSMAN','SYSTEM','MDSYS','OLAPSYS','DMSYS','ORDSYS','EXFSYS','XDB','CTXSYS','WMSYS','OUTLN','ISMSYS','DBSNMP','TSMSYS')
 14  and chain_cnt>0 order by chain_cnt desc;
 15  cursor spetial is select owner,table_name from dba_indexes where status='UNUSABLE';
 16  begin
 17    for tablename in table_name loop
 18  execute immediate 'analyze table '|| tablename.owner ||'.'||tablename.table_name || ' compute statistics ';
 19  end loop;
 20    for c_spetial in spetial loop
 21  dbms_output.put_line('UNUSABLE index in ' || c_spetial.owner ||'.' ||c_spetial.table_name || ' , Can not analyze this table');
 22  end loop;
 23  open table_name2;
 24  loop
 25  fetch table_name2 into dbatables;
 26  if(table_name2%ROWCOUNT=0) then
 27  dbms_output.put_line('No Chained Rows Found !!!');
 28  else
 29  dbms_output.put_line(dbatables.chain_cnt || ' chained rows found in ' ||  dbatables.owner ||'.'|| dbatables.table_name);
 30  end if;
 31  exit when table_name2%NOTFOUND;
 32  end loop;
 33  end;
 34  /
UNUSABLE index in SCOTT.EMP , Can not analyze this table
No Chained Rows Found !!!




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31448824/viewspace-2136609/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/31448824/viewspace-2136609/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值