/Test/countall.sql

http://github.com/fishman/ctags · SQL · 43 lines · 40 code · 3 blank · 0 comment · 2 complexity · baa309dc30f12ac669a981250f037859 MD5 · raw file

  1. rem -----------------------------------------------------------------------
  2. rem URL: http://www.orafaq.com/scripts/plsql/countall.txt
  3. rem Filename: countall.sql
  4. rem Purpose: Count the number of rows for ALL tables in current schema
  5. rem using PL/SQL
  6. rem Date: 15-Apr-2000
  7. rem Author: Eberhardt, Roberto (Bolton) (reberhar@husky.ca)
  8. rem -----------------------------------------------------------------------
  9. set serveroutput on size 1000000
  10. DECLARE
  11. t_c1_tname user_tables.table_name%TYPE;
  12. t_command varchar2(200);
  13. t_cid integer;
  14. t_total_records number(10);
  15. stat integer;
  16. row_count integer;
  17. t_limit integer := 0; -- Only show tables with more rows
  18. cursor c1 is select table_name from user_tables order by table_name;
  19. BEGIN
  20. t_limit := 0;
  21. open c1;
  22. loop
  23. fetch c1 into t_c1_tname;
  24. exit when c1%NOTFOUND;
  25. t_command := 'SELECT COUNT(0) FROM '||t_c1_tname;
  26. t_cid := DBMS_SQL.OPEN_CURSOR;
  27. DBMS_SQL.PARSE(t_cid,t_command,dbms_sql.native);
  28. DBMS_SQL.DEFINE_COLUMN(t_cid,1,t_total_records);
  29. stat := DBMS_SQL.EXECUTE(t_cid);
  30. row_count := DBMS_SQL.FETCH_ROWS(t_cid);
  31. DBMS_SQL.COLUMN_VALUE(t_cid,1,t_total_records);
  32. if t_total_records > t_limit then
  33. DBMS_OUTPUT.PUT_LINE(rpad(t_c1_tname,55,' ')||
  34. to_char(t_total_records,'99999999')||' record(s)');
  35. end if;
  36. DBMS_SQL.CLOSE_CURSOR(t_cid);
  37. end loop;
  38. close c1;
  39. END;
  40. /