Counting no. of records from multiple tables; Oracle DB

后端 未结 2 1843
忘掉有多难
忘掉有多难 2021-01-20 06:02

I know i need to use this query to get the list of tables for a schema: select table_name from all_tables where owner=\'schema\'

I know the following query counts t

2条回答
  •  失恋的感觉
    2021-01-20 06:16

    You can use DBMS_XMLGEN.GETXMLTYPE function to do this in one shot:

    SQL> select table_name
      2       , to_number
      3         ( extractvalue
      4           ( dbms_xmlgen.getxmltype('select count(*) c from ' || table_name)
      5           , '/ROWSET/ROW/C'
      6           )
      7         ) cnt
      8    from user_tables
      9   order by table_name
     10  /        
    
    TABLE_NAME                            CNT
    ------------------------------ ----------
    ... [output removed] ...
    
    71 rows selected.
    

    But if your schema contains a lot of data, this might take a long time. Just selecting NUM_ROWS might be sufficient if estimations are ok as well.

    Regards,
    Rob.

提交回复
热议问题