Count ALL rows in databases

Hi experts!
I need the total number of ROWS in EACH database i have (All schema)
I've tried this for each DB
select sum(num_rows)
from sys.dba_tables
where owner like '%%'
i obtain the number of all rows for all schema in database.
I have many database, i use agent g10.0 and enterprice manager to query them.
I
've seen that in Enterprise Manager, when you select a Database Istance, then go on "administration" tab, and u click on TABLES link, you can see number of rows and last time the table was analyzed. How are they have been calculated? With table dba_tables? How can i query to obtain these values?
I know it's a stupid task but my boss wants this info :(

> I know it's a stupid task but my boss wants this info :(
Tell him two gazillion. Also tell him that the gazillion scale has been specifically created for managers like him with heads firmly stuck up the back side.
Anyway, here's some sample code. Note that you cannot use DBA_TABLES view. Object tables are not listed in there and they can contain rows (obviously). There is also the case of dealing with case and "weirdly" names tables - thus double quotes are needed.
I only did the first 10 tables.. It is stupid to just one, never mind all of them in database...
SQL> declare
2 type TStrings is table of varchar2(1000);
3
4 cursor c is
5 select '"'||owner||'"."'||object_name||'"' as TAB_NAME from dba_objects where object_type='TABLE' and rownum < 11 order by 1;
6
7 tabList TStrings;
8 sqlSelect varchar2(1000);
9 cnt integer;
10 total integer;
11
12 procedure W( line varchar2 ) is
13 begin
14 DBMS_OUTPUT.put_line( line );
15 end;
16 begin
17 total := 0;
18 open c;
19 loop
20 fetch c bulk collect into tabList limit 100;
21 for i in 1..tabList.Count
22 loop
23 sqlSelect := 'select count(*) from '||tabList(i);
24 begin
25 execute immediate sqlSelect into cnt;
26 total := total + cnt;
27 W( sqlSelect || ' ' || cnt || ' rows(s)' );
28 exception when OTHERS then
29 W( sqlSelect || ' ' || sqlerrm(sqlcode) );
30 end;
31 end loop;
32 exit when c%NOTFOUND;
33 end loop;
34 close c;
35 W( total|| ' gazillion rows in the database' );
36 end;
37 /
select count(*) from "SYS"."CLU$" 10 rows(s)
select count(*) from "SYS"."COL$" 43696 rows(s)
select count(*) from "SYS"."CON$" 2898 rows(s)
select count(*) from "SYS"."FILE$" 5 rows(s)
select count(*) from "SYS"."ICOL$" 2184 rows(s)
select count(*) from "SYS"."IND$" 1434 rows(s)
select count(*) from "SYS"."PROXY_ROLE_DATA$" 0 rows(s)
select count(*) from "SYS"."SEG$" 3032 rows(s)
select count(*) from "SYS"."UET$" 0 rows(s)
select count(*) from "SYS"."UNDO$" 11 rows(s)
53270 gazillion rows in the database
PL/SQL procedure successfully completed.
SQL> PS. Cursor needs fine tuning as certain table objects cannot be directly accessed via a SELECT statement (e.g. nested tables, overflow IOT tables, etc).

Similar Messages

  • No Count all Rows in Discover Plus

    Hello,
    in Discoverer Desktop it is possible to count all rows (menue: sheet|Count all Rows) for a query. In Discoverer Plus Version 9.0.4 i am missing this feature. Is there a work around for this problem?
    Franz

    Thanks Marcus,
    i know, but it is a very slow way if you are selecting 10000 records. I don't understand why Oracle is not be able do add this feature like in the Desktop to Plus.
    Franz

  • 'Count all rows' in Disco Plus?

    Hi all - I can't find an option to Count All Rows in disco plus. This is something my users use all the time in Desktop - is it included in Plus?
    In Desktop, it is under menu item 'Sheet'
    Thanks!
    Scott

    Hi Scott
    Sorry that was removed from Discoverer Plus so you won't find a button for it. Having that there would force Discoverer to have to run the entire query just to give you the total count. Oracle considered this a waste of resource and query effort, which I sort of agree with because I can see what they are getting at, and so removed it.
    Best wishes
    Michael

  • Count all rows of a Database table

    I want to count all the rows of a table.
    I have made correctly the connection with the database and all the other things (make a statement, make the query and the resultSet), I use the MySQL server v4.0.17
    Here is the code I use:
    int count=0;
    String temp=null;
    String query = "SELECT COUNT(*) FROM customers";//customers is my Database Table
    try {
    rs = stmt.executeQuery(query);
    }//end try
    catch(Exception exc) {
    createFeatures.PlayErrorSound(registerRenter);
    Optionpane.showMessageDialog(registerRenter,
    "MESSAGE", "ERROR", JOptionPane.ERROR_MESSAGE);
    }//end catch
    try {
    while(rs.next()) {
    count++; //I use this variable in order to count the rows because the resultSet doesn't tell me the answer
    countLine=rs.getInt(1);
    }//end while
    }//end try
    catch(Exception exc) {
    createFeatures.PlayErrorSound(registerRenter);
    Optionpane.showMessageDialog(registerRenter,
    "MESSAGE", "ERROR", JOptionPane.ERROR_MESSAGE);
    }//end catch
    count=count++; //i increase it aggain because if the rows are initial 0 i want to make it 1
    temp = String.valueOf(count);//i use this command in order to display the result into a jtextfield
    Any help is appreciated!!!!!

    This program will work just fine against mysql:
    mport java.util.*;
    import java.io.*;
    import java.sql.*;
    public class Test {
    public static void main(String []args) {
    String url= "jdbc:mysql://localhost/adatabase";
    String query = "select count(*) from foo2";
    String createQuery="create table foo2(f1 int)";
    String dropQuery="drop table foo2";
    String insertQuery="insert into foo2 values(1)";
    Properties props = new Properties();
    props.put("user", "auser");
    props.put("password", "xxxxx");
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    System.out.println("Connecting to the msql server");
    Connection con = DriverManager.getConnection(url, props);
    Statement stmt = con.createStatement();
    try {
    stmt.executeUpdate(dropQuery);
    } catch(SQLException e) {}
    stmt.executeUpdate(createQuery);
    stmt.executeUpdate(insertQuery);
    stmt.executeUpdate(insertQuery);
    PreparedStatement pstmt = con.prepareStatement(query);
    System.out.println("***Executing a select");
    ResultSet rs = pstmt.executeQuery();
    while (rs.next()) {
    System.out.println("RowCount="+ rs.getString(1));
    rs.close();
    pstmt.close();
    stmt.close();
    con.close();
    } catch(Exception e) {
    System.out.println(e.getMessage());
    }

  • Count all rows in all tables

    Is there any easy way to count all of the rows in all of the tables?
    I am currently generating a list of tables by selecting from all_tables and then turning that into individual select count(*) statements using awk.
    I'm guessing there is probably some other better method?

    Jim,
    I have a sql script which I call numrows that will dynamically create select count(*) statements from the dba_tables dictionary view... It does not display all of the tables in the entire database, but instead prompts you for a particular schema. Maybe you can adjust to do what you want it to..
    Regards,
    David
    +++beginning of script
    -- Script to count the number of rows in tables
    set serveroutput on
    declare
    numrows integer;
    cursor c1 is select table_name from user_tables order by table_name;
    function rowcount(tablename in user_tables.table_name%type)
    return integer is
    cursornum integer;
    numrows integer;
    ignore integer;
    begin
    cursornum := dbms_sql.open_cursor;
    dbms_sql.parse(cursornum,
    'select count(*) from ' &#0124; &#0124; tablename,
    dbms_sql.v7);
    dbms_sql.define_column(cursornum, 1, numrows);
    ignore := dbms_sql.execute(cursornum);
    ignore := dbms_sql.fetch_rows(cursornum);
    dbms_sql.column_value(cursornum, 1, numrows);
    dbms_sql.close_cursor(cursornum);
    return numrows;
    end;
    begin
    dbms_output.enable(10000);
    dbms_output.put_line('Table Rows ');
    dbms_output.put_line('------------------------------ ----------');
    for c1rec in c1 loop
    numrows := rowcount(c1rec.table_name);
    dbms_output.put_line(rpad(c1rec.table_name, 32) &#0124; &#0124; numrows);
    end loop;
    end;
    null

  • Count all rows in user_tables

    Hi,
    Any one could help me to write a pl/sql procedure to get the total number of all the rows of user_tables?
    Thanks!

    Have a look at the following thread:
    'count rows of all rows of all tables urgent'
    count rows of all rows of all tables urgent

  • Count total rows in database?

    Hello all,
    Is there a way to query the database for the total number of rows.... without using ANALYZE STATISTICS? (That would cause the db to sometimes use COST instead of RULE based optimization, slowing it down significantly.)
    I know I could could brute force a total row count with something like:
    spool get_total_rows.sql
    SELECT 'SELECT COUNT(*) FROM '||owner||'.'||table_name||';'
    FROM ALL_TABLES;
    spool off
    ...then run get_total_rows and manually add all the counts.
    But it just seems like there must be a cleaner way to do it.
    Thanks much,
    Natasha

    ok. here you have that information:
    ALL_TABLES
    ALL_TABLES describes all relational tables accessible to the current user. To gather statistics for this view, use the SQL ANALYZE statement.
    Related Views
    DBA_TABLES describes all relational tables in the database.
    USER_TABLES describes all relational tables owned by the current user. This view does not display the OWNER column.
    Note:
    Columns marked with an asterisk are populated only if you collect statistics on the table with the ANALYZE statement or the DBMS_STATS package.
    Column Datatype NULL Description
    OWNER
    VARCHAR2(30)
    Owner of the table
    TABLE_NAME
    VARCHAR2(30)
    Name of the table
    TABLESPACE_NAME
    VARCHAR2(30)
    Name of the tablespace containing the table; NULL for partitioned, temporary and index-organized tables
    CLUSTER_NAME
    VARCHAR2(30)
    Name of the cluster, if any, to which the table belongs
    IOT_NAME
    VARCHAR2(30)
    Name of the index-organized table, if any, to which the overflow entry belongs. If IOT_TYPE column is not null, this column contains the base table name.
    PCT_FREE
    NUMBER
    Minimum percentage of free space in a block; NULL for partitioned tables
    PCT_USED
    NUMBER
    Minimum percentage of used space in a block; NULL for partitioned tables
    INI_TRANS
    NUMBER
    Initial number of transactions; NULL for partitioned tables
    MAX_TRANS
    NUMBER
    Maximum number of transactions; NULL for partitioned tables
    INITIAL_EXTENT
    NUMBER
    Size of the initial extent in bytes; NULL for partitioned tables
    NEXT_EXTENT
    NUMBER
    Size of the secondary extension bytes; NULL for partitioned tables
    MIN_EXTENTS
    NUMBER
    Minimum number of extents allowed in the segment; NULL for partitioned tables
    MAX_EXTENTS
    NUMBER
    Maximum number of extents allowed in the segment; NULL for partitioned tables
    PCT_INCREASE
    NUMBER
    Percentage increase in extent size; NULL for partitioned tables
    FREELISTS
    NUMBER
    Number of process freelists allocated to this segment; NULL for partitioned tables
    FREELIST_GROUPS
    NUMBER
    Number of freelist groups allocated to this segment; NULL for partitioned tables
    LOGGING
    VARCHAR2(3)
    Logging attribute; NULL for partitioned tables
    BACKED_UP
    VARCHAR2(1)
    Has table been backed up since last change
    NUM_ROWS*
    NUMBER
    Number of rows in the table
    BLOCKS*
    NUMBER
    Number of used data blocks in the table
    EMPTY_BLOCKS*
    NUMBER
    Number of empty (never used) data blocks in the table
    AVG_SPACE*
    NUMBER
    Average amount of free space, in bytes, in a data block allocated to the table
    CHAIN_CNT*
    NUMBER
    Number of rows in the table that are chained from one data block to another, or which have migrated to a new block, requiring a link to preserve the old ROWID
    AVG_ROW_LEN*
    NUMBER
    Average length of a row in the table in bytes
    AVG_SPACE_FREELIST
    _BLOCKS
    NUMBER
    The average freespace of all blocks on a freelist
    NUM_FREELIST_BLOCKS
    NUMBER
    The number of blocks on the freelist
    DEGREE
    VARCHAR2(10)
    The number of threads per instance for scanning the table
    INSTANCES
    VARCHAR2(10)
    The number of instances across which the table is to be scanned
    CACHE
    VARCHAR2(5)
    Whether the cluster is to be cached in the buffer cache (CACHE | NOCACHE)
    TABLE_LOCK
    VARCHAR2(8)
    Whether table locking is enabled or disabled
    SAMPLE_SIZE
    NUMBER
    Sample size used in analyzing this table
    LAST_ANALYZED
    DATE
    Date on which this table was most recently analyzed
    PARTITIONED
    VARCHAR2(3)
    Indicates whether this table is partitioned. Set to YES if it is partitioned.
    IOT_TYPE
    VARCHAR2(12)
    If this is an index-organized table, then IOT_TYPE is IOT, IOT_OVERFLOW, or IOT_MAPPING. If this is not an index-organized table, then IOT_TYPE is NULL.
    TEMPORARY
    VARCHAR2(1)
    Can the current session only see data that it place in this object itself?
    SECONDARY
    VARCHAR2(1)
    Whether the trigger is a secondary object created by the ODCIIndexCreate method of the Oracle9i Data Cartridge (Y |N)
    NESTED
    VARCHAR2(3)
    Is the table a nested table?
    BUFFER_POOL
    VARCHAR2(7)
    The default buffer pool for the object. NULL for partitioned tables
    ROW_MOVEMENT
    VARCHAR2(8)
    Whether partitioned row movement is enabled or disabled
    GLOBAL_STATS
    VARCHAR2(3)
    For partitioned tables, indicates whether statistics were collected for the table as a whole (YES) or were estimated from statistics on underlying partitions and subpartitions (NO)
    USER_STATS
    VARCHAR2(3)
    Were the statistics entered directly by the user?
    DURATION
    VARCHAR2(15)
    Indicates the duration of a temporary table:
    SYS$SESSION: the rows are preserved for the duration of the session
    SYS$TRANSACTION: the rows are deleted after COMMIT
    Null for a permanent table
    SKIP_CORRUPT
    VARCHAR2(8)
    Whether Oracle ignores blocks marked corrupt during table and index scans (ENABLED) or raises an error (DISABLED). To enable this feature, run the DBMS_REPAIR.SKIP_CORRUPT_BLOCKS procedure.
    MONITORING
    VARCHAR2(3)
    Whether the table has the MONITORING attribute set
    Try with ALL_TABLES and post if the results were zero too
    Joel P�rez

  • Calculating a count of rows where value matches another column value in the same table

    Hi,
    I'm struggling to do something in DAX that seems to me should be super easy (coming from a SQL world)!
    That is to count all rows in column 1 where the value matches the current value for column 1?
    E.g something like this:
    [Col2]=Count of rows in [Col1] where value = this.[Col1]
    Where the results are as in the table below:
    Col1, Col2
    A, 2
    A, 2
    B, 1
    Anyone?
    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    Thanks, that's perfect! 
    I knew it had to be something so simple, but after spending over an hour banging my head against those exact functions I couldn't get anything working!
    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

  • Present a total count of rows

    I'd like to present a total count of rows in the bottom of a report.
    how would you recommand me to do it???
    the point is that it must be presented in each report so i thought to add some HTML code to "After Rows" section in the report template. but i need a variable (or some substitution string) which will contain the total count. but how do i define a substitution string?

    as i mentioned i need to present a total count in the buttom of each report in my application. therefore I think it's reasonable to add a code in the report template, which present some variable which count all rows in a report.
    #TOTAL_ROWS# doesn't work if i place it on the template html code, though it works fine if i place it in the report region definition:
    <br><b>Total Number of Results:</b> #TOTAL_ROWS#.</br>
    why can't i use #TOTAL_ROWS# as a template variable? and how can i do that?

  • View all rows

    Hi,
    I want to view all rows of a workbook in Discoverer Desktop but I can't. I have a worksheet where I can view 10000 rows. But when I select Sheet --> Count all rows the answer is 83165.
    How can I view the rest of rows? I have the Sheet --> View all rows option disabled.
    Thanks.

    Hi there,
    Look at Tools-->Options-->Query Governor. The "Limit retrieved date to" is set to 10,000. Change as required or de-select the option.
    Regards,
    John

  • Table name and count of rows in that table through out the database

    Hi All,
    how to find the table_name and the number of rows in that table for all in a database.
    Bhargava S Akula.

    Hi,
    Something like this
    create function table_count(
       owner       dba_tables.table_name%type
      ,table_name  dba_tables.table_name%type)
       return number
    is
       the_count   number;
       stmt        varchar2(2000);
    begin
       stmt := 'select count(*) from ' || owner || '.' || table_name;
       execute immediate stmt
                    into the_count;
       return the_count;
    exception
       when others
       then
          return 0;
    end table_count;
    select owner, table_name, table_count(owner, table_name)
      from dba_tables
    where 1 = 2; -- remove this  Regards
    Peter

  • Query to return ALL rows even those with zero counts

    Hi,
    The following query will return only those rows that have a non zero count value:
    select c.id, a.name, count(*) as XYZ from CON c, CUST a
    where c.help !='1' and (c.id = a.id) group by c.id, a.name order by c.id;
    The results are:
    1 ME 3
    3 YOU 4
    What i want is to return all rows in CUST and the count, XYZ, that correspond to each row in CUST that matches the whare condition above, even if the count is zero.
    ie
    1 ME 3
    2 WE 0
    3 YOU 4
    Can this be done?

    You may want to get the counts then do the outer join. If you simply count with an outer join you will get 1 for 'WE' because there is a row in the cust table with 'WE'. This may work for you;
    with
      cust as (
       select 1 id, 'ME' name from dual union all
       select 2 id, 'YOU' name from dual union all
       select 3 id, 'WE' name from dual),
      con as (
       select 1 id, '2' help from dual union all
       select 1 id, '2' help from dual union all
       select 1 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual union all
       select 2 id, '2' help from dual)
    -- end of test data 
    select a.id, a.name, nvl(c.cnt,0) xyz
    from cust a, 
       (select id, help, count(*) cnt
       from con
       where help !='1'
       group by id, help) c
    where a.id = c.id(+)

  • How to delete all rows data from database

    Hello All.
    I have a database username 'abc'. This database contain 123 tables & have many data.
    I want to empty all the database. Is it possible that clear all the database with a single query.
    if yes then kindly tell me about the query .
    Thanks
    Diamond

    Keep in mind that you cannot rollback the truncate command.
    Once you truncate a table all of it's data AND statistics are gone.
    If you do not want to use PL/SQL to delete all rows you can generate a script by SQL
    SCOTT@ORCL> SELECT ' TRUNCATE TABLE '|| TABLE_NAME||';' FROM USER_TABLES;
    'TRUNCATETABLE'||TABLE_NAME||';'
    TRUNCATE TABLE BONUS;
    TRUNCATE TABLE SALGRADE;
    TRUNCATE TABLE DEPT_LOV;
    TRUNCATE TABLE TITLE;
    TRUNCATE TABLE TEST_DATE;
    TRUNCATE TABLE DEPT;
    TRUNCATE TABLE REP;
    TRUNCATE TABLE REP_PARAM;
    TRUNCATE TABLE EMP;
    10 rows selected.
    SCOTT@ORCL> SELECT 'DELETE FROM '|| TABLE_NAME||';' FROM USER_TABLES;
    'DELETEFROM'||TABLE_NAME||';'
    DELETE FROM BONUS;
    DELETE FROM SALGRADE;
    DELETE FROM DEPT_LOV;
    DELETE FROM TITLE;
    DELETE FROM TEST_DATE;
    DELETE FROM DEPT;
    DELETE FROM REP;
    DELETE FROM REP_PARAM;
    DELETE FROM EMP;
    10 rows selected.
    SCOTT@ORCL>You can save the output in a .sql file and run it.
    Regards,
    Tony

  • Procudure to count all the rows in a all tables in the schema

    When I run the following store procedure to count all the rows in all the tables I crash my sql Plus editor:
    CREATE OR REPLACE PROCEDURE TC_TABLEROWCOUNT(OWNER IN varchar2)
    IS
    row_count number;
    cursor get_tab is
    select table_name, num_rows
    from all_tables
    where owner='MAXDEV';
    begin
    dbms_output.put_line('Checking Record Counts for schema maxdev ');
    FOR get_tab_rec IN get_tab LOOP
         BEGIN
              EXECUTE IMMEDIATE 'select count(*) from '||get_tab_rec.table_name
              INTO row_count;
              EXCEPTION WHEN OTHERS THEN
                        dbms_output.put_line('Error counting rows for table '
                                                 ||get_tab_rec.table_name);
         END;
    END LOOP;
    END;
    What am I doing wrong.
    Thanks for any help Tony

    The boss gave me 5 pages of tables and wants to know how many row there are in each table. There is a problem of one DB being out of sync with another.
    But I have managed to work the problem though.
    here is the working code:
    CREATE OR REPLACE PROCEDURE TC_TABLEROWCOUNT (
    TableOwner IN varchar2)
    IS
    row_count number;
    vTable varchar2(30);
    v_sqlstmt varchar2(100);
    cursor get_tab is
    select table_name, num_rows
    from all_tables
    where owner = TableOwner;
    begin
    dbms_output.put_line('Checking Record Counts for schema maxdev ');
    FOR get_tab_rec IN get_tab LOOP
    vTable := get_tab_rec.table_name;
    v_sqlstmt := 'SELECT count(*) from '||vTable;
    EXECUTE IMMEDIATE v_sqlstmt into row_count;
    dbms_output.put_line('Table '|| get_tab_rec.table_name || ' Row ' || row_count);
    END LOOP;
    END;

  • Need Query to that generate count of rows of all tables

    Hi
    i need a query which gives the result of no.of rows in talbe and coresponding table name.
    And then i need to compare the same with other DB schema
    Thanks in advance

    Hi User,
    We can also get the count of rows for all the tables associated with a User, we can create a custom function which
    uses the table name to return results.
      CREATE OR REPLACE FUNCTION TAB_ROWS_CNT (TAB_NAME IN VARCHAR2)
       RETURN NUMBER
    AS
       TAB_CNT   NUMBER :=0;
    BEGIN
       EXECUTE IMMEDIATE 'select count(*) from ' || TAB_NAME
          INTO TAB_CNT;
       RETURN TAB_CNT;
    END;And query,
    SELECT TABLE_NAME, TAB_ROWS_CNT (TABLE_NAME) ROW_CNT
      FROM USER_TABLES;Which gets us the count of Individual Tables for a user.
    This is an just that we can do in this way also. But, use which is optimal.
    Thanks,
    Shankar

Maybe you are looking for

  • Dist. of Header Condition based on the material Value

    Hi All, I have one query regarding the header Condition.i have selected the Calculation type as B - fixed amount  (mandatory) for a particular Condition type and also selected the header and Item condition indicator.Now if the material have more than

  • I can't sign in to the iTunes Store in my Apple TV

    I had to reset, restart, unplug and many other alternative to try to connect my apple tv but it failed and a msj said that I need to set the network time (it is impossible to do it) I don't know if was the updated or other issue with the IOS, my netw

  • Full screen mode problems on Windows XP

    I've added a full-screen feature to an application.  Everything works fine for me.  MacOS+Safari.  But I another developer on my team is having problems... He says, "In my Windows XP environment using Internet Explorer 8.0.6xxx I experience the follo

  • To suppress "WBS HIERARCHY" for every WBS Element Node

    Hi All, Below are WBS nodes in the report. For every node, "WBS HIERARCHY" is repeating. WBS HIERARCHY C-11-5210 WBS HIERARCHY C-11-5214 WBS HIERARCHY C-11-5216 WBS HIERARCHY C-11-8521 WBS HIERARCHY C-15-1000 Is there any way to suppress this, so tha

  • Authorization for query

    Dear Experts, If i do not have access to S_RS_COMP for activity 16 (Execute) but i have full authorization for S_RS_BCS for broadcasting can I broadcast queries. Thanks, Mihir