Count Number of Record for every Table
set serveroutput on
DECLARE
v_count NUMBER;
v_stmt VARCHAR2(100);
CURSOR c1 IS SELECT owner'.'table_name table_name FROM all_tables
WHERE owner = 'SCOTT';
BEGIN
FOR c1_rec IN c1 LOOP
v_stmt := 'SELECT COUNT(*) FROM ' c1_rec.table_name;
EXECUTE IMMEDIATE v_stmt INTO v_count;
DBMS_OUTPUT.PUT_LINE('The number of rows in table ' c1_rec.table_name' is: 'v_count);
END LOOP;
END;
Output
SQL> /
The number of rows in table SCOTT.BONUS is: 0
The number of rows in table SCOTT.DEPT is: 4
The number of rows in table SCOTT.EMP is: 14
The number of rows in table SCOTT.SALGRADE is: 10
PL/SQL procedure successfully completed

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home