码迷,mamicode.com
首页 > 数据库 > 详细

ORACLE 统计查看每一个表的行数

时间:2018-03-05 17:06:14      阅读:330      评论:0      收藏:0      [点我收藏+]

标签:表行数   into   空间   comm   varchar   ora   oracl   begin   查看   

create or replace procedure sp_static_tab

  /**
   * 统计所有表的行数
   */
is
 vv_table_name varchar2(64); 
 vi_table_rows number;
 vv_sqlstr     varchar2(200);
 
 cursor r_cursor is
 select table_name from user_tables
  where substr(table_name,1,3)<>‘BIN‘; 
 
begin
 EXECUTE IMMEDIATE ‘truncate table tb_static_tab‘;
   
  OPEN r_cursor;
 LOOP 
  FETCH r_cursor INTO vv_table_name;
  exit when r_cursor %notfound;
  vv_sqlstr:=‘select count(1) from ‘|| vv_table_name;
  
  begin     
   EXECUTE IMMEDIATE vv_sqlstr
      into vi_table_rows;
     
   insert into tb_static_tab
   (
    static_date ,
    table_name  ,
    table_rows  ,
    table_size
   )
   values(
    sysdate,
    vv_table_name,
    vi_table_rows,
    null
   );
  end;
   
 end loop;
  close r_cursor;  
  commit;
    
end;

 

/****************************************
--建表
create table tb_static_tab
(
 static_date date    , -- 统计日期
 table_name varchar2(64),  -- 表名
 table_rows number,       -- 表行数
 table_size number         -- 表占空间 byte
);
*****************************************/

ORACLE 统计查看每一个表的行数

标签:表行数   into   空间   comm   varchar   ora   oracl   begin   查看   

原文地址:https://www.cnblogs.com/cx6872/p/8509553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!