Considering that I have a Schema named SBST
I want to find all empty tables list in this SBST Schema. Is there any PL/SQL procedure to find that. I found few. But those were using user tables where I was not able specify the Schema name SBST.
I was using this
select table_name from dba_tables where owner ='SBST'
having count(*)=0 group by table_name
What’s wrong in the above query?
Similar to @shareef’s answer, but using dynamic SQL to avoid having to create the temporary
.sqlfile. You’ll needdbms_outputto be visible, e.g. withset serveroutput onin SQL*Plus – don’t know about Toad.Using
all_tablesseems more useful thandba_tableshere so you know you can select from the tables it lists. I’ve also included the schema in thefromclause in case there other users have tables with the same name, and so you can still see it if you’re connected as a different user – possibly avoiding synonym issues too.Specifically what’s wrong with your query… you’ve got the
havingandgroup byclauses the wrong way around; but it will always return no data anyway because if SBST has any tables thencount (*) from dba_tablesmust be non-zero, so thehavingalways matches; and if it doesn’t then, well, there’s no data anyway so there’s nothing for thehavingto match against. You’re counting how many tables there are, not how many rows are in each table.