SQL脚本

--如下语句可直接列出对应报表:
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;
/

--查询表的数据条数、表名、中文表名
select a.TABLE_NAME,a.num_rows, b.COMMENTS
from user_tables a, user_tab_comments b
WHERE a.TABLE_NAME = b.TABLE_NAME
order by TABLE_NAME;

posted @ 2019-11-08 10:43  liutoliu  阅读(164)  评论(0编辑  收藏  举报