ITPub博客

首页 > 数据库 > Oracle > Oracle查询数据库中所有表和分区表的记录数

Oracle查询数据库中所有表和分区表的记录数

原创 Oracle 作者:feelpurple 时间:2015-10-18 14:22:38 0 删除 编辑
--查询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博客 ” ,链接:https://blog.itpub.net/26506993/viewspace-1814771/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: oracle 11g 创建 job
请登录后发表评论 登录
全部评论

注册时间:2014-08-01

  • 博文量
    404
  • 访问量
    1673941