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!

Add the row counts of all tables

TeaTreeOct 19 2016 — edited Oct 19 2016

DB version: 11.2.0.4

I have few tables in my schema. I need to run count(*) on each table and then add them up.

In the below example I am manually running COUNT(*) on each table and sum it up and I get 23. Can I do this using PL/SQL or SQL ?

I don't want to use user_tables.num_rows for this purpose because num_rows is accurate only when the stats are up-to-date.

SQL> show user

USER is "SCOTT"

SQL>

SQL>

SQL> select table_name from user_tables;

TABLE_NAME

------------------------------

DEPT

EMP

BONUS

SALGRADE

SQL> select count(*) from DEPT;

  COUNT(*)

----------

         4

SQL> select count(*) from EMP;

  COUNT(*)

----------

        14

SQL> select count(*) from BONUS;

  COUNT(*)

----------

         0

SQL> select count(*) From SALGRADE;

  COUNT(*)

----------

         5

SQL> select 4+14+0+5 from dual;

  4+14+0+5

----------

        23

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 16 2016
Added on Oct 19 2016
15 comments
1,427 views