본문 바로가기

wif LiNoUz/Ubuntu

Row count for all tables in an Oracle Schema



Row count for all tables in an Oracle Schema

http://www.etload.com/2013/03/counts-of-all-tables-in-schema.html


Fist method:- 




select table_name,
       to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) c from '||owner||'.'||table_name)),'/ROWSET/ROW/C')) as count
from all_tables
where owner = 'EDW'


Second Method:-
May not give you the correct results some time 

select
   table_name,
   num_rows counter
from
   ALL_tables or DBA_TABLES
where
   owner = 'EDW'
order by
   table_name;




Third Method:-

Declare
    v_count integer;
begin

    for x in (select table_name, owner from all_tables
              where owner = 'SCHEMA_NAME')
    loop
        execute immediate 'select count(*) from ' || x.table_name
            into v_count;
        INSERT INTO Table_Counts(TABLE_NAME,SCHEMA_NAME,RECORD_COUNT,CREATED)
        VALUES (x.table_name,x.owner,v_count,SYSDATE);
    end loop;

end;

'wif LiNoUz > Ubuntu' 카테고리의 다른 글

Fedora 설치 및 오라클  (1) 2013.03.06
vi  (0) 2013.01.21
정규식 표현  (0) 2012.12.12
커널 다운  (0) 2012.10.31
우분투 ojdbc14 드라이버 어따 복사하냐  (0) 2012.10.10