- 论坛徽章:
- 0
|
数据库中好多表都是空的~怎样将不为空的表的所有表删选出来?
把下面的存为test.sql,然后执行它即可.
- drop table test;
- create table test(coll varchar(100));
- set serveroutput on
- Declare
- cursor cur is
- select table_name from user_tables;
- bcur user_tables.table_name%TYPE;
- x int :=0;
- Begin
- --set serveroutput on;
- open cur;
- DBMS_OUTPUT.PUT_LINE('以下为空表:');
- LOOP
- delete from test;
- FETCH cur into bcur;
- exit when cur%NOTFOUND;
- execute immediate 'insert into test select count(*) from '||bcur;
- select coll into x from test;
- IF (x=0) then
- dbms_output.put_line(bcur);
- --dbms_output.put_line(x);
- END if;
- END LOOP;
- END;
- /
- drop table test;
复制代码 |
|