http://space.itpub.net/7104/viewspace-133950
oracle中所有表记录数统计
create table A
(
USERNAME VARCHAR2(20),
TABLENAME VARCHAR2(50),
JS VARCHAR2(10)
)
create or replace procedure p_getcount
as
miCount INTEGER;
t_owner varchar2(40);
t_table varchar2(40);
BEGIN
FOR c_tab IN (SELECT owner,table_name FROM dba_tables where owner not in ('SYS','SYSTEM','CTXSYS','PERFSTAT','WMSYS','EXFSYS','SYSMAN')) LOOP
--dbms_output.put_line('select count(*) from ' || c_tab.owner||'.'||c_tab.table_name || '');
--dbms_output.put_line( c_tab.owner||'.'||c_tab.table_name);
t_owner := c_tab.owner;
t_table := c_tab.table_name;
EXECUTE IMMEDIATE 'select count(*) from ' || c_tab.owner||'.'||'"'||c_tab.table_name||'"' || '' into miCount;
--dbms_output.put_line(rpad(c_tab.table_name,30,'.') || lpad(miCount,10,'.'));
INSERT INTO A VALUES (C_TAB.OWNER,C_TAB.TABLE_NAME,miCount);
END LOOP;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line( t_owner||'.'||t_table);
RAISE;
commit;
end;