首頁 >資料庫 >mysql教程 >Oracle数据库中找出空表

Oracle数据库中找出空表

WBOY
WBOY原創
2016-06-07 14:58:021191瀏覽

Oracle数据库中找出空表 无 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

Oracle数据库中找出空表
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 * FROM dba_segments WHERE blocks <= 1 AND segment_type = 'TABLE';
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn