- 不要求准确
select t.table_name,t.num_rows from user_tables t;
这种方式,说不准确,是因为他的分析,不是实时的,user_tables里有个字段,last_analyzed,上次分析时间。可能从上次分析完,已经修改了很多次了,但是他没有重新分析,那么数据量的统计,就是不准确的。
要获得一张表的数据量,从 user_tables中查 num_rows,使用count()函数。区别是,一个是估计,不准确,但是速度贼快;一个精确,但是速度慢,这就是第二种。
2. 要求准确
使用count 函数
3. 既然 user_tables 不准确是因为没有分析,那么我们可以手动执行分析。
analyze table tablename compute statistics;
执行语句,分析一张表,分析后,num_rows统计就准确了。
如果要查每张表的数量,可以批量生产 分析语句
select 'analyze table '||table_Name||' compute statistics;'from user_TABLES;
例如user_tables有A,B,C,D表
上面的结果会有4条记录
analyze table A compute statistics;
analyze table B compute statistics;
analyze table C compute statistics;
analyze table D compute statistics;
生成分析语句后,执行这些分析语句,user_tables表里 num_rows 字段就可靠了。但是表多的话,这个分析语句的效率,还没有试过。可能没有count速度快,毕竟分析的话,就不只是count,可能还分析了其他方面的数据。
不知道还有没有其他办法,快速准确的统计每张表的数据量呢?