我需要显示所有没有记录的表.
我试过了,
select * from user_all_tables where (select count(*) from user_all_tables)=0;
Run Code Online (Sandbox Code Playgroud)
但它似乎没有用.我该如何重新设计此查询?谢谢.
如果分析了所有表,则可以检查num_rows表的列user_tables.
否则,您将需要PL/SQL来完成这项工作.这将输出当前用户的所有表而没有记录(all_tables如果您需要其他用户的表,则使用):
Set Serveroutput On;
Declare
cnt PLS_INTEGER;
Begin
For c In ( Select table_name From user_tables ) Loop
Execute Immediate 'Select Count(*) From "' || c.table_name || '" where rownum=1'
Into cnt;
If( cnt = 0 ) Then
dbms_output.put_line( c.table_name );
End If;
End Loop;
End;
Run Code Online (Sandbox Code Playgroud)