Live ORACLE

if you are Oracle Developer ,than this Blog most likely will make you happy.

About my Blog

This Blog particularized for Oracle Developers ... you will see interesting Codes for SQL , PL/SQL as well as new ideas for Developer Suite and Client Tools that will help you in your professional life ... and I hope I reach for your satisfaction.

About Me

I'm Hany Freedom , 25 years old , I live in EL-Minia City in Egypt , I'm Moderator at ArabOUG.org the best Arabic Forum for ORACLE on the Net. if you interested to know more about me .... just Click Here.

Count the number of rows for ALL tables in current schema


rem ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-

rem Filename: countall.SQL

rem Purpose: Count the number of rows for ALL tables in current SCHEMA

rem using PL/SQL

rem Date: 15-Apr-2000

rem Author: Eberhardt, Roberto (Bolton) (reberhar@husky.ca)

rem ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-

SET serveroutput on size 1000000


DECLARE

t_c1_tname user_tables.table_name%TYPE;

t_command VARCHAR2(200);

t_cid INTEGER;

t_total_records NUMBER(10);

stat INTEGER;

row_count INTEGER;

t_limit INTEGER := 0; -- Only show tables with more rows

CURSOR c1 IS

SELECT table_name

FROM user_tables

ORDER BY table_name;

BEGIN

t_limit := 0;



OPEN c1;



LOOP

FETCH c1 INTO t_c1_tname;



EXIT WHEN c1%NOTFOUND;



t_command := 'SELECT COUNT(0) FROM '

||t_c1_tname;



t_cid := dbms_sql.open_cursor;



dbms_sql.Parse(t_cid,t_command,dbms_sql.native);



dbms_sql.Define_column(t_cid,1,t_total_records);



stat := dbms_sql.EXECUTE(t_cid);



row_count := dbms_sql.Fetch_rows(t_cid);



dbms_sql.Column_value(t_cid,1,t_total_records);



IF t_total_records > t_limit THEN

dbms_output.Put_line(Rpad(t_c1_tname,55,' ')

||To_char(t_total_records,'99999999')

||' record(s)');

END IF;



dbms_sql.Close_cursor(t_cid);

END LOOP;



CLOSE c1;

END;

/



Share/Save/Bookmark

0 comments:

Post a Comment



Newer Posts Older Posts Home Page
 
http://www.dpriver.com/images/sqlpp-banner-2.png

Thanks for reading my Blog ... you Visitor Number :-