Skip to content

Instantly share code, notes, and snippets.

@mujahidk
Last active July 21, 2017 13:43
Show Gist options
  • Save mujahidk/4a01ee892ff377ac81ee to your computer and use it in GitHub Desktop.
Save mujahidk/4a01ee892ff377ac81ee to your computer and use it in GitHub Desktop.
Oracle: Row count of all tables which has ID column
SET SERVEROUTPUT ON
DECLARE ROW_COUNT NUMBER(10);
BEGIN
-- All user tables with column ID.
FOR TAB IN (SELECT TABLE_NAME FROM USER_TAB_COLUMNS WHERE COLUMN_NAME = 'ID' ORDER BY TABLE_NAME)
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT(1) FROM ' || TAB.TABLE_NAME INTO ROW_COUNT;
DBMS_OUTPUT.PUT_LINE( TAB.TABLE_NAME || ',' || ROW_COUNT );
END LOOP;
END;
/
SET SERVEROUTPUT ON
DECLARE ROW_COUNT NUMBER(10);
BEGIN
-- All user tables.
FOR TAB IN (SELECT TABLE_NAME FROM USER_TABLES ORDER BY TABLE_NAME)
LOOP
EXECUTE IMMEDIATE 'SELECT COUNT(1) FROM ' || TAB.TABLE_NAME INTO ROW_COUNT;
DBMS_OUTPUT.PUT_LINE( TAB.TABLE_NAME || ',' || ROW_COUNT );
END LOOP;
END;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment