Oracle 테이블 사이즈 및 테이블별 카운트 출력 스크립트



1. 테이블 사이즈 조회


  SELECT owner,

         segment_name,

         bytes,

         SUM (bytes / 1024 / 1024)

    FROM dba_segments

   WHERE segment_type = 'TABLE'

         AND owner NOT IN

                ('SYSTEM',

                 'SYS',

                 )

GROUP BY owner, segment_name, bytes order by bytes desc;

 

2. 테이블별 카운트 출력


set serveroutput on

exec dbms_output.enable(1000000);

declare

      CURSOR cur_mytables IS

        select * from dba_tables where owner in (

'TEST'     

,'JOB'   

)         order by owner, table_name;

      v_cnt NUMBER;

    begin

      FOR i IN cur_mytables

      LOOP

        EXECUTE IMMEDIATE ('SELECT /*+ parallel ('||i.table_name||',4) */ COUNT(*) FROM '||i.owner || '.' ||i.table_name) INTO v_cnt;

        --EXECUTE IMMEDIATE ('SELECT COUNT(*) FROM '||i.table_name) INTO v_cnt;

        DBMS_OUTPUT.PUT_LINE(i.owner|| ',' || i.table_name||','||v_cnt);

   END LOOP;

 end;

/ 


블로그 이미지

운명을바꾸는자

IT와 함께 살아가는 삶

,