【试验】三个用于日常监控开发库与对应测试库的存储过程

 

  
  
  
  
  1. -检查表,列是否一致 
  2.  
  3. create or replace procedure check_tab_col(v_schema varchar2) 
  4. as 
  5.      isfindtab number; 
  6.      isfindcol number; 
  7. begin 
  8.     dbms_output.put_line('Sechema '||v_schema||' begin searching...'); 
  9.     dbms_output.put_line(chr(10)); 
  10.     for i in (select table_name from dba_tables where owner=v_schema) loop 
  11.             select count(*) into isfindtab from dba_tables@dblink_testdbc where owner=v_schema 
  12.                                                                       and table_name=i.table_name; 
  13.             if isfindtab=0 then 
  14.                --没有找到表 
  15.                dbms_output.put_line(rpad(i.table_name,30,' ')||' is lost in testdbc'); 
  16.             else 
  17.                --找到表,则继续搜索列 
  18.                for j in (select column_name from dba_tab_columns where owner=v_schema and table_name=i.table_name) loop 
  19.                       select count(*) into isfindcol from dba_tab_columns@dblink_testdbc where owner=v_schema 
  20.                                                                      and table_name=i.table_name 
  21.                                                                      and column_name=j.column_name; 
  22.                       if isfindcol=0 then 
  23.                           --没有找到列 
  24.                            dbms_output.put_line('alter table '||i.table_name||' add('||j.column_name); 
  25.                       end if; 
  26.                end loop; 
  27.             end if; 
  28.     end loop; 
  29.     dbms_output.put_line(chr(10)); 
  30.     dbms_output.put_line('Sechema '||v_schema||' end searching...'); 
  31.     exception when others then 
  32.         null
  33. end check_tab_col; 
  34.  
  35. --检查索引 
  36.  
  37. create or replace procedure check_indexes(v_schema varchar2) 
  38. as 
  39.     n_isfind number; 
  40. begin 
  41.    dbms_output.put_line(v_schema||'  Index Searching'); 
  42.    for c in(select index_name,table_name from dba_indexes where table_owner=v_schema) loop 
  43.           select count(*) into n_isfind from dba_indexes@dblink_testdbc 
  44.                                                 where index_name=c.index_name 
  45.                                                 and table_name=c.table_name 
  46.                                                 and table_owner=v_schema; 
  47.           if n_isfind=0 then 
  48.                dbms_output.put_line(rpad(c.table_name,30,' ')||'  '||c.index_name); 
  49.           end if; 
  50.    end loop; 
  51. end check_indexes; 
  52.  
  53. --检查序列 
  54.  
  55. create or replace procedure check_seq(v_schema varchar2) 
  56. as 
  57.     n_isfind number; 
  58. begin 
  59.    dbms_output.put_line(v_schema||' sequence '); 
  60.    for c in(select SEQUENCE_NAME from dba_sequences where SEQUENCE_OWNER=v_schema) loop 
  61.           select count(*) into n_isfind from dba_sequences@dblink_testdbc 
  62.                                                 where SEQUENCE_NAME=c.SEQUENCE_NAME 
  63.                                                 and SEQUENCE_OWNER=v_schema; 
  64.           if n_isfind=0 then 
  65.                dbms_output.put_line('sequence '||rpad(c.SEQUENCE_NAME,30,' ')||' is lost in testdbc'); 
  66.           end if; 
  67.    end loop; 
  68. end

 

你可能感兴趣的:(oracle,职场,监控,休闲)