达梦数据库SQL脚本之统计表数据量

--drop table table_count;
create table table_count (owner varchar(100),table_name varchar(100),cnt int);
declare
v_owner VARCHAR2(100);
v_tabname VARCHAR2(100);
stmt  VARCHAR2(200);
num_rows number;
begin
    for rec in (select owner,table_name from dba_tables where owner='DMHR' order by 1, 2)
    loop
        select rec.owner,rec.table_name into v_owner,v_tabname from dual; 
        stmt := 'select count(*) from "' || v_owner || '"."' || v_tabname || '"';
        EXECUTE IMMEDIATE stmt INTO num_rows;  
        EXECUTE IMMEDIATE 'insert into table_count values('''||v_owner||''','''||v_tabname||''','''||to_number(num_rows)||''');';
    end loop;
end;
--truncate table table_count;
select count(*) from table_count;
select * from table_count order by cnt desc;
select count(*) from dba_tables;

欢迎关注我的博客《Jackin's Blog - 知识改变命运》学习分享更多知识

你可能感兴趣的:(达梦数据库,数据库)