您的位置:首页 > 数据库

解决统计表行数与All_Tables(Dba_Tables)对应表的Num_Rows不一致的问题

2017-03-29 21:31 323 查看
我们在使用ORACLE中,有时要将表中数据导出。当常常发现统计表行数与All_Tables(Dba_Tables)对应表的Num_Rows的值不一致。这是因为没有采用analyze分析表的缘故。

可在sqlplus中采用下面第1条语句,重新对表进行分析统计即可。后面2条语句是对表的索引记录重新分析统计和清除。

解决如下:

1)select ‘ analyze table ‘ || A.TABLE_NAME ||’ compute statistics;’ from all_tables A where A.OWNER=’用户名’;

2)select ‘ analyze table ‘ || A.TABLE_NAME | |’ compute statistics for all indexes;’ from all_tables A where A.OWNER=’用户名”;

3)select ‘ analyze table ‘ || A.TABLE_NAME || ‘ delete statistics ;’ from all_tables A where A.OWNER=’用户名”;

例如:

1)select ‘ analyze table ‘ || A.TABLE_NAME || ‘ compute statistics;’ from all_tables A where A.OWNER=’JZUSER’;

2)select ‘ analyze table ‘ || A.TABLE_NAME | |’ compute statistics for all indexes;’ from all_tables A where A.OWNER=’JZUSER’;

3)select ‘ analyze table ‘ || A.TABLE_NAME || ‘ delete statistics ;’ from all_tables A where A.OWNER=’JZUSER’;

将以上三条语句查询出来的结果,分别拷贝并粘贴至sqlplus中执行,然后重新执行

select * from all_tables A where A.OWNER=’用户名’ and A.NUM_ROWS > 0

例如:select * from all_tables A where A.OWNER=’JZUSER’ and A.NUM_ROWS > 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库