oracle 查询数据库中每个表的数据量
oracle 查询库中每个表的数据量
·
select t.table_name,a.comments,t.num_rows from user_tables t
left join user_tab_comments a on a.table_name = t.TABLE_NAME order by t.NUM_ROWS desc
但是这个语句有个问题,就是统计出来的数据量并不是实时的。会出现统计的数量跟实际数量不符的情况。
目前了解到的办法是 执行以下语句:
analyze table 【table_name 】compute statistics;
存储过程为
CREATE OR REPLACE PROCEDURE "analyzealltable" AS
BEGIN
for cur_item in (select table_name from user_tables) loop
begin
execute immediate 'analyze table '|| cur_item.table_name
|| ' compute statistics';
exception
when others then
dbms_output.put_line('分析表异常:'||sqlerrm);
end;
end loop;
-- routine body goes here, e.g.
-- DBMS_OUTPUT.PUT_LINE('Navicat for Oracle');
END;
中括号里面的是你要计算的表的名字,然后再执行上面的那条语句,查询出来就是最新的统计数量了,但是如果表比较多的话,需要创建一个存储过程,利用游标批量运行。
!!!!!注意
如果出现 调存储过程00302
说明有表名和用户名一样
删除即可
更多推荐
已为社区贡献1条内容
所有评论(0)