Identify a table with maximum rows in Oracle

后端 未结 7 1410
猫巷女王i
猫巷女王i 2021-01-13 08:15

I have a set of tables in Oracle and I would like to identify the table that contains the maximum number of rows.

So if, A has 200 rows, B has 345 rows and C has 120

相关标签:
7条回答
  • 2021-01-13 08:46

    The table in your schema that has max rows:

    with data as 
    (
     select table_name,
            to_number(extractvalue(xmltype(
                      dbms_xmlgen.getxml (
                     ' select count(*) c from ' || table_name)),
                      '/ROWSET/ROW/C')) countrows
     from   user_tables
    )
    select table_name, countrows
    from   data 
    where  countrows = (select max(countrows)
                        from   data);
    

    dbms_xmlgen.getxml(' select .... ') is extremely flexible.

    0 讨论(0)
提交回复
热议问题