Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

To get each table count from multiple schema's

PS SPJan 18 2022

Hello Expers,
I have many schema's and each schema has many tables. I need to generate report on each table count. I tried these 3 options from here
Out of which extracting count from dba_tables is easiest way but this count is not accurate.
Other 2 are failing.
First one is taking toomuch time and failing.
  DECLARE
       lo_sql varchar2(4000);
       lo_count NUMBER;
       BEGIN
       FOR list_uctabl IN
       (SELECT UC_NAME, UC_<XXXXXX>, <XXXXXX>, TABLE_NAME FROM V_XXXXX_USECASE_SCOPE
       LEFT OUTER JOIN ALL_TABLES
       ON <XXXXXX> = OWNER AND <XXXXXX> = TABLE_NAME WHERE UC_SRST = ''CREATED'')
       LOOP
            DBMS_OUTPUT.PUT_LINE(list_uctabl.<XXXXXX> || list_uctabl.<XXXXXX> );
            IF list_uctabl.TABLE_NAME IS NULL OR list_uctabl.<XXXXXX> IS NULL OR list_uctabl.<XXXXXXX> IS NULL THEN
               lo_count := 0;
           ELSE
               BEGIN
                   lo_sql := ''SELECT COUNT(1) FROM "'' || list_uctabl.<XXXXXX> || ''"."'' || list_uctabl.<XXXXXX>
                   || ''"'';
                   EXECUTE IMMEDIATE lo_sql INTO lo_count;
               EXCEPTION
                   WHEN OTHERS THEN
                   lo_count := 0;
               END;
           END IF;
           INSERT INTO TABL_CNTREC (UC_NAME, <XXXXXX>, <XXXXXX>, RECORD_COUNT)
           VALUES (list_uctabl.UC_NAME, list_uctabl.<XXXXXX>, list_uctabl.<XXXXXX>, lo_count);
       END LOOP;
       COMMIT;
       END;       
       ';

second approach is as well failing <dbms_xmlgen.getxml>

its failing with 
ORA-06512: at "SYS.DBMS_XMLGEN", line 176. 
I have even tried with this option :

table_name not in ('LINK$')

Can you please suggest me best approach also if I need to take count from dba_tables how to execute dbma stat package on every schema in automated way?
This post has been answered by Frank Kulash on Jan 19 2022
Jump to Answer
Comments
Post Details
Added on Jan 18 2022
15 comments
2,214 views