0

I am trying to create a table that store table names and count of the table.

I already have the list of tables. How to use this list to get all the count for the tables?

The result should be like this:

TABLE_NAME   NUM_ROWS
------------ --------
tableName1   result from select count(*) from tableName1     
...

Any ideas?

Thanks in advance.

4
  • Count of tables means total no of table in that list or count of records in that table??? Commented Aug 8, 2018 at 15:23
  • 2
    Like this? Commented Aug 8, 2018 at 15:28
  • means : select count(*) from table_name; Commented Aug 8, 2018 at 16:16
  • @user228: I think that's what Alex's example does. Commented Aug 8, 2018 at 16:53

1 Answer 1

2

For a Quick and Dirty solution try.

SELECT TABLE_NAME, NUM_ROWS
FROM USER_TABLES

Oracle stores a wealth of metadata information. You can query into the metadata to get a reasonable estimate. The actual number of rows can be off depending on when the table was last analyzed and how often the table is updated..

If that is not a viable option, you will need to write a pl/sql procedure to loop through the tables (querying USER_TABLES) and using something like EXECUTE IMMEDIATE to select the count of the number of rows on that table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.