Home FAQ Previous Next

How to find number of records in each table of the Oracle schema.



Suppose, there is HR schema containing 7 tables.
Let's use some dynamic SQL: 

DECLARE
   cntr       NUMBER (10);
   tbl_name   user_tables.table_name%TYPE;
BEGIN
   FOR rec IN (SELECT table_name
                 FROM all_tables
                WHERE owner = 'HR')
   LOOP
      EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM hr.' || rec.table_name
                   INTO cntr;

      DBMS_OUTPUT.put_line (rec.table_name || ' ' || cntr);
   END LOOP;
END;
/



The output will be as follows:
REGIONS 4 LOCATIONS 23 DEPARTMENTS 27 JOBS 19 EMPLOYEES 107 JOB_HISTORY 10 COUNTRIES 25
Home FAQ Previous Next