File: countall.sql

package info (click to toggle)
geany 2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 39,300 kB
  • sloc: ansic: 168,600; cpp: 77,562; sh: 5,344; makefile: 1,694; cs: 1,233; javascript: 1,024; python: 580; f90: 537; vhdl: 504; sql: 503; lisp: 436; fortran: 389; php: 278; ada: 201; ruby: 163; java: 131; asm: 131; perl: 119; cobol: 88; tcl: 77; erlang: 73; xml: 66; ml: 27; sed: 16; pascal: 15; haskell: 6
file content (43 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
rem -----------------------------------------------------------------------
rem URL:        http://www.orafaq.com/scripts/plsql/countall.txt
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;
/