結構損壞檢查指令碼

zhangsharp20發表於2016-10-24
export ORACLE_SID=DWTH
sqlplus / as sysdba <<EOF
set feedback off
set serveroutput on
declare
v_sql varchar2(4000);
v_sqlerrm varchar2(4000);
cursor cur_tab is
 select dt.owner,dt.table_name from dba_tables dt
   where dt.owner in ('ODS_BUFF_KKX','SGDM','ZS_OUTPUT','NOVELL_IAS','ODS_BUFF_GJHZ','EIC','ODS_UNV','SGDW','ERPPSUSER','ODS_BUFF_JJFL','ODS_ZCQSM','EPBI_SG','ODS_BUFF_JRGK','ODS_BUFF_ZDC','ODS_BUFF_TGYERP','ODS_ZHTJ_VIEW','SGODSESA','EIC_SJZX','ODS_BUFF_CWGK','ODS_BUFF','SGDC','OWB_OWNER','SGODS_JY','SGDC_DXP','NOVELL','PSDSS_DCHK','PSDSS_YXYWGKPT','PSDSS_JLSCDDPT','DATAVIEWER','YXYQ','PSDSS_MID','OMAC','EPBI','EPBI_DXP','PSDSS_SGDC','PSDSS_BUFF_SG','PSDSS_BUFF','PSDSS_SJTS','PSDSS_BUSI','SG_EESMP')
 minus
(
 select owner,table_name from crpt_check.crpt_check_err_log
  union all
 select owner,table_name from crpt_check.crpt_check_log
);
begin
  dbms_output.enable(buffer_size=>null);
  for cur_1 in cur_tab loop
    begin
      dbms_output.put_line(cur_1.owner||'.'||cur_1.table_name);
      v_sql:='analyze table '||cur_1.owner||'.'||cur_1.table_name||' validate structure cascade';
      dbms_output.put_line(v_sql);
      execute immediate v_sql;
      dbms_output.put_line(cur_1.owner||'.'||cur_1.table_name||' analyzed');
      insert into crpt_check.crpt_check_log(correct_log,exec_date,owner,table_name) values (cur_1.owner||'.'||cur_1.table_name||' analyzed',sysdate,cur_1.owner,cur_1.table_name);
      commit;
      exception
        when others then
          v_sqlerrm:=sqlerrm;
          dbms_output.put_line('error:'||cur_1.owner||'.'||cur_1.table_name||' not analyzed,'||sqlerrm);
          insert into crpt_check.crpt_check_err_log(error_log,exec_date,owner,table_name) values ('error:'||cur_1.owner||'.'||cur_1.table_name||' not analyzed,'||v_sqlerrm,sysdate,cur_1.owner,cur_1.table_name);
          commit;
    end;
  end loop;
end;
/
set feedback on
set serveroutput off
quit;
EOF
echo "over"

其中:
crpt_check.crpt_check_err_log、crpt_check.crpt_check_log為兩張配置表,用於檢視資料和排除資料使用
結構如下:

log varchar2(4000);
insert_date sysdate;
owner varchar2(30);
table_name varchar2(30);

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29802484/viewspace-2127002/,如需轉載,請註明出處,否則將追究法律責任。

相關文章