Friday, 26 May 2017

Query to Find the List of Table names and the Record Count


The following query will give the list of tablename and the corresponding row count. 


  1. SELECT table_name, total_count FROM (  
  2.   SELECT table_name, extractvalue(xml_data,'/ROWSET/ROW/TOTAL_COUNT/text()') AS total_count FROM(  
  3.       SELECT table_name, XMLTYPE(dbms_xmlgen.getxml('SELECT COUNT(1) AS TOTAL_COUNT FROM '||table_name))  AS xml_data   
  4.       FROM (  
  5.         SELECT table_name   
  6.         FROM user_tables WHERE ROWNUM>=0    
  7.         )  
  8.       )   
  9.     )  
  10. ORDER BY total_count DESC;  
  11.   
  12. The output looks something like this.  
  13.   
  14. TABLE_NAME                | TOTAL_COUNT    
  15. --------------------------|-----------    
  16. CLIENT                    |  9539    
  17. EBA_DEMO_PROJ_TASK_TODOS  |  9    
  18. EBA_DEMO_MD_TASK_TODOS    |  9    
  19. ITRAVEL_TABLES            |  80    
  20. TCC_EMP                   |  8    
  21. INVHEAD                   |  76073    
  22. EBA_DEMO_FILE_PROJECTS    |  73    
  23. EBA_UT_CHART_TASKS        |  73    
  24. EBA_DEMO_PROJ_TASK_LINKS  |  7    




No comments:

Post a Comment