• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Oracle 统计用户下表的数据量实现脚本

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

要想统计用户下所有表的数据量,可以查看user_tables,此表里面是统计信息,当然这个可能不太准,要想非常精确,需要直接count表。下面的脚本有异常不中断,可以重复执行的特点。

create table bk_count_tables
(
 owner VARCHAR2(30),
 table_name VARCHAR2(30),
 part_col varchar2(100),--分区字段
 row_s number,
 gather_time date
);
create index ind_bct_own_table on bk_count_tables(owner,table_name);
set serveroutput on
declare
cursor c_cursor is select s.OWNER, s.TABLE_NAME, col.column_name part_col
  from dba_tables s,
    (select owner,
        name,
        listagg(column_name, ',') within group(order by null) column_name
      from (select owner, name, column_name
          from dba_part_key_columns
         where owner in ('TEST')
          and object_type = 'TABLE'
          and name not like 'BIN$%'
         union all
         select owner, name, column_name
          from dba_subpart_key_columns
         where owner in ('TEST')
          and object_type = 'TABLE'
          and name not like 'BIN$%')
     group by owner, name) col
 where s.OWNER in ('TEST')
  and not regexp_like(table_name, '[0-9]{3,8}')
  and s.table_name not like '%BAK%'
  and s.table_name not like '%A2K%'
  and s.table_name not like 'BK%'
  and s.table_name not like 'BIN%'
  and s.OWNER = col.owner(+)
  and s.TABLE_NAME = col.name(+)
order by s.TABLE_NAME ;
c_row c_cursor%rowtype;
t_rows number;
begin
 for c_row in c_cursor loop
  begin
   execute immediate 'select count(*) from bk_count_tables where owner=:1 and TABLE_NAME=:2 and rownum=1' 
   into t_rows using c_row.OWNER,c_row.TABLE_NAME ;
   if(t_rows = 0) then 
    execute immediate 'select count(*) from "'||c_row.TABLE_NAME||'"' into t_rows;
    insert into bk_count_tables values(c_row.OWNER,c_row.TABLE_NAME,c_row.part_col,t_rows,sysdate);
    commit; 
    end if;
  EXCEPTION
   WHEN OTHERS THEN
   DBMS_OUTPUT.PUT_LINE(c_row.OWNER||'---'||c_row.TABLE_NAME);
   rollback; 
  end;
 end loop;
end;
/

总结

以上所述是小编给大家介绍的Oracle 统计用户下表的数据量实现脚本,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对极客世界网站的支持!


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MySQL 事务autocommit自动提交操作发布时间:2022-02-08
下一篇:
mysql、oracle默认事务隔离级别的说明发布时间:2022-02-08
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap