LoginSignup
0

More than 5 years have passed since last update.

ORACLEでレコードが存在するテーブル一覧を出力する

Posted at
SET SERVEROUTPUT ON
DECLARE
  N NUMBER;
BEGIN
  FOR C IN (SELECT TABLE_NAME FROM USER_TABLES) LOOP
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || C.TABLE_NAME INTO N;
    IF N > 0 THEN
        DBMS_OUTPUT.PUT_LINE(C.TABLE_NAME || ': ' || N);
    END IF;
  END LOOP;
END;
/

[実行例]

M_CODE: 100
T_FILE: 3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0