Solved

get table record count in oracle

Posted on 2009-04-12
5
790 Views
Last Modified: 2013-12-18
want to count records for all the tables in a schema. For example,
SQL> select table_name from user_tables order by table_name;
T1
T2
T3

3 rows selected.

SQL> select count(1) from t1;
         2
Can one complex query be written to get the records per table? The result is
table_name   count_records
T1                 2
T2                 5
T3                 4
...
0
Comment
Question by:jl66
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 24127825
if your statistics are up to date you can get close approximations by selecting "num_rows" from user_tables

select table_name,num_rows from user_tables;

if you really want to count all of the rows...


select table_name,
to_number(extractvalue(xmltype(dbms_xmlgen.getxml('select count(*) X from '||table_name))
          ,'/ROWSET/ROW/X')) count
from user_tables

note, if you have many large tables this could take a long time.
0
 

Author Comment

by:jl66
ID: 24133897
Excellent!
Is it possible to loop all tables in one schema and get certain columns out in each table?
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24134285
I'm not sure what you're asking.

If I've answered your original question please close this question.

When you open a new question, please include sample input and expected output to illustrate what you're looking for.
When you close this question there will be an option to ask a related question if you want to tie these two together
0
 

Author Closing Comment

by:jl66
ID: 31569400
Excellent.
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 24137050
glad I could help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question