0

Within my database I would like to know the total amount of rows.

I am able to find out the amount of rows in a certain table in my database with this query:

select count (*) From TABLE_NAME;

However, is there a more efficient way, rather than repeating this for every table?

java123999
  • 6,974
  • 36
  • 77
  • 121

1 Answers1

0

You may use this pl/sql block to know the total no of rows in all tables.

DECLARE  
   t_name VARCHAR2(100);  
   total_rows NUMBER;  
   t_count NUMBER;  
BEGIN  
  total_rows := 0;  
  t_count := 0;  

  FOR rec IN (SELECT table_name FROM user_tables)  
  LOOP  
    EXECUTE IMMEDIATE 'select count(1) from '||rec.table_name  
    INTO t_count;  

    total_rows := total_rows + t_count;  
  END LOOP;  

  dbms_output.put_line('Total no of Rows: '||total_rows);  
EXCEPTION  
  WHEN OTHERS THEN  
    dbms_output.put_line(SQLERRM);  
END;     
Raghvendra
  • 124
  • 1
  • 10