介绍
怎么在Oracle中对用户中表的数据量进行统计?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
要想统计用户下所有表的数据量,可以查看user_tables,此表里面是统计信息,当然这个可能不太准,要想非常精确,需要直接计数表。下面的脚本有异常不中断,可以重复执行的特点。
create table bk_count_tables ( ,owner VARCHAR2 (30), ,table_name VARCHAR2 (30), ,part_col varchar2(100)——分区字段 ,row_s 数字, gather_time 日期 ); create index  ind_bct_own_table 提醒bk_count_tables(所有者、table_name); set serveroutput 声明 cursor c_cursor  is select s.OWNER, s.TABLE_NAME, col.column_name part_col 得到dba_tables 年代,才能 ,,,(select 所有者, ,,,,,,,, ,,,,,,,listagg (column_name, & # 39; & # 39;), within 集团(order by  null), column_name ,,,,,得到(select 所有者,名字,,column_name ,,,,,,,,得到dba_part_key_columns ,,,,,,,,where owner 拷贝(& # 39;测试# 39;) ,,,,,,,,,以及object_type =, & # 39;表# 39; ,,,,,,,,,以及name not like & # 39;本$ % & # 39; ,,,,,,,union 所有 ,,,,,,,,select 所有者,名字,column_name ,,,,,,,,得到dba_subpart_key_columns ,,,,,,,,where owner 拷贝(& # 39;测试# 39;) ,,,,,,,,,以及object_type =, & # 39;表# 39; ,,,,,,,,,以及name not like & # 39;本$ % & # 39;) ,,,,group by 老板名字),坳 ,where s.OWNER 拷贝(& # 39;测试# 39;) 的,,以及not regexp_like (table_name, & # 39; [0 - 9] {3 8} & # 39;) 以及才能s.table_name not  like & # 39; %贝克% & # 39; 以及才能s.table_name not  like & # 39; % A2K % & # 39; 以及才能s.table_name not  like & # 39; BK % & # 39; 以及才能s.table_name not  like & # 39;本% & # 39; 以及才能s.OWNER =, col.owner (+) 以及才能s.TABLE_NAME =, col.name (+) order by  s.TABLE_NAME ; c_row c_cursor % rowtype; t_rows 数量; 开始 ,for c_row  c_cursor 拷贝;循环 ,开始 ,,execute immediate & # 39; select count(*),得到bk_count_tables where 所有者=:1,以及TABLE_NAME=: 2,以及rownum=1 & # 39;, ,,into t_rows  using c_row.OWNER c_row.TABLE_NAME ; ,,如果(t_rows =, 0), then ,,,execute immediate & # 39; select count(*),得到“& # 39;| | c_row.TABLE_NAME | | & # 39;“& # 39;, into t_rows; ,,,insert into bk_count_tables 价值(c_row.OWNER、c_row.TABLE_NAME c_row.part_col, t_rows, sysdate); ,,,提交,, ,,,最终获得;如果; ,异常 ,,WHEN OTHERS 然后 ,,DBMS_OUTPUT.PUT_LINE (c_row.OWNER | | & # 39;——& # 39; | | c_row.TABLE_NAME); ,,,回滚; 结束才能; ,最终获得;循环; 结束;/
看完上述内容,你们掌握怎么在Oracle中对用户中表的数据量进行统计的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注行业资讯频道,感谢各位的阅读!