Oracle查詢資料庫中所有表和分割槽表的記錄數

feelpurple發表於2015-10-18
--查詢SCOTT使用者中所有表的記錄數
declare
  v_count number;
  query   varchar2(4000);
begin
  for i in (select table_name
              from all_tables
             where owner = 'SCOTT'
             order by 1) loop
    query := 'select count(*) from "' || i.table_name || '"';
    execute immediate query
      into v_count;
    dbms_output.put_line(rpad(i.table_name, 35, ' ') || '-----' || v_count);
  end loop;
end;

--檢視分割槽表的行數
declare
  v_count number;
  query   varchar2(4000);
begin
  for i in (select table_name,partition_name
              from user_tab_partitions
             where table_name='DDM_TRANSACTION_LOG'
             order by 1) loop
    query := 'select count(*) from ' || i.table_name || ' partition(' || i.partition_name || ')' || '';
    execute immediate query
      into v_count;
    dbms_output.put_line(rpad(i.partition_name, 35, ' ') || '-----' || v_count);
  end loop;
end;

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

相關文章