Oracle某个表有记录,为什么user_tables中num_rows为空

我数据库有一个表T。T中有5条记录,为什么通过user_tables查询的时候,表T的num_rows为空?

首先你使用1、select t.table_name,t.num_rows from user_tables t;查询不到结果时,可以手动执行分析user_tables表,过程如下:1)
create or replace function count_rows(table_name in varchar2,owner in varchar2 default null)
return number authid current_user IS
num_rows number;
stmt varchar2(2000);
begin
if owner is null then
stmt := 'select count(*) from "' || table_name || '"';
else
stmt := 'select count(*) from "' || owner || '"."' || table_name || '"';
end if;
execute immediate stmt
into num_rows;
return num_rows;
end;
2)、
分析表:
analyze table tablename compute statistics;
之后,再执行select t.table_name,t.num_rows from user_tables t;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-18
要先对表T做统计分析追问

统计分析?是Oracle本身做统计分析吗?user_tables是系统表,应该具有实时性啊,能不能再详细些,谢谢?

追答

对表T做分析,user_tables才有体现:
execute dbms_stats.gather_table_stats(ownname => 'owner',tabname => 'table_name' ,estimate_percent => null ,cascade => true);
或者
analyze table table_name compute statsticstic;

本回答被提问者和网友采纳
第2个回答  2015-03-19
Oracle不是实时的对表进行分析的,需要手动执行分析,参考楼上的语句
相似回答