Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get table record count in oracle

Posted on 2009-04-12
5
Medium Priority
?
805 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
  • 3
  • 2
5 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

926 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