今天查询下数据库中一个表的具体记录数,使用
select count(1) from [tablename],执行起来速度非常慢,所以想看看是否有更好的办法,发现,在tabs表已经存在了该表记录数据了,直接运行如下sql就可以了
select TABLE_NAME, CC.num_rows, CC.last_analyzed
from tabs CC
经过查询资料发现,从tabs表中获取的数据不是非常准确,在tabs表中存在一个字段last_analyzed,有最后分析的日期,好像都不是最新,可能导致数据不是非常准确,可以通过在command下面执行EXEC dbms_stats.gather_table_stats('【空间名称】','【tablename】',cascade=>true);,可以刷新tabs表中的num_rows列,以及最后更新时间
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
Connected as rep_hea
SQL> EXEC dbms_stats.gather_table_stats('【username】','【tablename】',cascade=>true);
--单个表统计数据的统计数据更新
PL/SQL procedure successfully completed
SQL> EXEC dbms_stats.gather_schema_stats('【username】',estimate_percent=>100,cascade=> TRUE);
--更新整个用户所有表的统计数据更新
如何快速的获取oracle数据库中表中记录行数,不使用select count(1)方式
最新推荐文章于 2021-04-10 10:42:04 发布