Identify a table with maximum rows in Oracle

后端 未结 7 1408
猫巷女王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:32

    select max(select count(*) from A union select count(*) from B...)
    

    should work.

    edit: if you want something dynamic, you can build a string in PL/SQL with each "count(*)" subquery (for example, listing the table names from USER_TABLES), and then execute te main query with:

    execute immediate 'select max('||subquery||')'
    

提交回复
热议问题