首页 > 数据库 > 数据库开发技术 > 得到表的记录数和占用的存储空间脚本
以前都是要查哪个表的就写个sql得到。呵呵
现在整理为一个脚本吧。供参考
[@more@]--得到表的记录数和占用的空间
--dbms_output.enable(100000);
set serveroutput on
declare
cnt number;
col varchar2(300);
begin
for rec in (select segment_name,sum(bytes)/1024/1024 mbytes
from user_segments
where segment_type = 'TABLE'
group by segment_name)
loop
begin
execute immediate 'select count(*) from '||
rec.segment_name into cnt;
exception
when others then
cnt := 0;
end;
if cnt is null
then
cnt := 0;
end if;
select 'Table: '||rpad(rec.segment_name,30)||
' Count: '||rpad(to_char(cnt),10)||
' Space: '||rpad(to_char(rec.mbytes,999999.99),10)||' MBytes.'
into col
from dual;
dbms_output.put_line(col);
end loop;
end;
/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/802415/viewspace-823051/ ,如需转载,请注明出处,否则将追究法律责任。