oracle表空间中空表统计方法示例介绍
程序员文章站
2023-11-22 14:43:16
复制代码 代码如下: declare v_table tabs.table_name%type; v_sql varchar2(888); v_q number; curs...
复制代码 代码如下:
declare
v_table tabs.table_name%type;
v_sql varchar2(888);
v_q number;
cursor c1 is
select table_name tn from tabs;
type c is ref cursor;
c2 c;
begin
dbms_output.put_line('以下为空数据表的表名:');
for r1 in c1 loop
v_table :=r1.tn;
v_sql :='select count(*) q from '||v_table;
open c2 for v_sql;
loop
fetch c2 into v_q;
exit when c2%notfound;
if v_q=0 then
dbms_output.put_line(v_table);
end if;
end loop;
close c2;
end loop;
exception
when others then dbms_output.put_line('error occurred');
end;