Number of rows in all of your tables.

Hello,
If I want to discover the number of rows in all of my tables (e.g. I own 20 tables and each table has 50 rows), why is the following code not providing the answer:
SELECT count(*)
FROM (SELECT table_name
FROM all_tables
WHERE owner = 'SHIRISH');
Thanks in advance,
Shirish

Yes, EXTEND, FIRST and LAST are related to using collections. Actually, I think you're wrong about using 0 to indx. Looking at his code, I believe that would need to be 1 to indx. Which of course, demonstrates the reason to use FIRST and LAST. That way you don't have to make assumptions about the index range. I wouldn't have kept the index separately. I would have use the COUNT attribute when adding elements to the collection. Actually, I probably wouldn't have used the extra collection at all given what that code does ...
declare
    type ttab_table_name is table of user_tables.table_name%type;
    tab_table_name ttab_table_name;
    vint_cnt integer;
begin
    select table_name
    bulk collect into tab_table_name
    from user_tables;
    for i in tab_table_name.first .. tab_table_name.last loop
        execute immediate 'SELECT COUNT (*) FROM '
            || tab_table_name(i) into vint_cnt;
        dbms_output.put_line(rpad(tab_table_name(i), 35, ' ')
            || '- ' || to_char(vint_cnt, '999,999,999'));
    end loop;
end;
/

Similar Messages

  • Number of rows inside a cell in table

    Hie all,
              I have a requirement in that I have to create the number of rows inside the cell of table. I did it using the subforms as a body page of a row.
    but facing problems when you have number of rows such as data truncation and overlapping of rows..
    Please help.

    Hi,
    You can also create table inside the cell of the column by following steps:
    1.Select the Cell of the Column in table.
    2.Go to Table -->Insert-->and choose as per your requirement(You can adjust the row ans column as per your requirement).
    3. Go to Pallette-->Border and hide the border if not required.
    This is will not create problem of overlapping or truncation.
    Regards,
    Shweta

  • Number of rows in all tables

    Hi,
    I need to query in max db to find number of rows exist in each and every table. Is there any query we can use to find in a single shot?
    Example:
    S.NO Table Name      Number of rows
    1          A                    3000
    2          B                     5000

    Hi,
    it depends on the database version you are using. In the newer database versions 7.8 and 7.9 you can use the system table files  to get the total number of records.
    SELECT sum (entrycount) from files where type = 'TABLE'
    This includes the MaxDb systemtables as well.
    If you want to count the number of rows of one schema only use the following join command between tables and files:
    SELECT sum(entrycount) from files f, tables t where f.type = 'TABLE'
    AND tableid = fileid and SCHEMANAME = '<schema>'
    e.g.
    SELECT sum(entrycount) from files f, tables t where f.type = 'TABLE'
    AND tableid = fileid and SCHEMANAME = 'SUPERU'
    The system table files contains for each table the entrycount, which is exaclty the number of records.
    Precondition: All file directory counters for all tables have been created sucessfully. This is the case if table Sysupdatecounterwanted is empty. The creation is implictely executed.
    Regards, Christiane

  • How to control the number of rows selected from a sybase database table?

    Hi, JDBC guru,
    I'm working on project using Sybase 11.9.x database.We need to process a record in a table,first select it from the table,then do some computing,finally write it to a dbf file, if the above steps succeed,remove the original row in the table.Quite evidently, all these operation should be put into one transaction. But how can I select just a number of rows from the sybase database table?
    Any hints?
    Thank you in advance.
    Regards,
    Jusitne

    Statement stmt...
    stmt.setMaxRows(20);

  • How to find number of rows in tables

    Hi,
    Can you please help me how to know the number of rows in all the tables databsae.
    Thanks In Advance,

    Just found out that the behaviour changed in 11.2.0.2:
    SQL> select * from v$version where rownum = 1
    BANNER                                                                         
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production         
    1 row selected.
    SQL> select owner, table_name, column_value cnt
      from (select owner, table_name, 'count(ora:view("' || owner || '","' || table_name || '"))' xq
              from all_tables
             where table_name in ('EMP', 'DEPT')),
           xmltable (xq) order by owner, table_name desc
    OWNER                          TABLE_NAME                     CNT  
    FLEET                          EMP                            14   
    FLEET                          DEPT                           4    
    MICHAEL                        EMP                            14   
    MICHAEL                        DEPT                           5    
    SCOTT                          EMP                            14   
    SCOTT                          DEPT                           4    
    STEFAN                         EMP                            14   
    STEFAN                         DEPT                           4    
    8 rows selected.

  • 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

  • Can we find the number of rows in table from the dump file

    Hi All,
    Can we find the number of rows in table from the dump file with out importing the table in to the database?
    Please let me know ,if any option is there.
    Thanks,
    Kumar.

    <s>Try to import with option SHOW=Y, that should skip the number of rows which are into a table from a dump file.</s><br>
    <br>
    Nicolas.<br>
    Oops, sorry, that doesn't show the number of lines...<br>
    Message was edited by: <br>
    N. Gasparotto

  • How to make a control table with the same number of rows of its itab

    I'm creating a control table, but it always have the maximum number of lines possible.
    How can I make it so that it has only the same number of rows of it's internal table?

    solved partialy with this:
    MODULE locka_lin OUTPUT.
      DATA: lin TYPE i.
      DESCRIBE TABLE t_obj LINES lin.
      table_con-lines = lin.
    ENDMODULE.                 "  OUTPUT
    but it still doent work when lin = 0
    any simple way to solve it on that case?
    Edited by: RagnaRock on May 5, 2010 6:00 PM

  • More Table Blocks in 11g with same number of rows as in 9i

    I was using SQL performance analyzer to compare performance difference between 9i and 11g databases.
    For this purpose I generated a trace file in 9i database and used it to build STS in 11g database.
    After runing two trials and comparison the report showed performance regression (comparing "buffer gets") while using following SQL statement
    *"SELECT * FROM EMP";*
    There were total 14 rows in emp table in both databases( i.e 9i and 11g)
    There was no plan change for above SQL statement in 11g database but still there was performance regression in 11g.
    After querying dba_tables view for number of blocks in emp table on both sides i found that EMP table in 9i database had 1 block where as in 11g emp table had 5 blocks (Even after using alter table emp move;)
    I am unable to understand why emp table has more number of blocks in 11g with same number of rows as in 9i emp table?

    user8916506 wrote:
    Below query was executed in 9i database.
    SQL> select extent_management,initial_extent,allocation_type from dba_tablespaces where tablespace_name='SYSTEM';
    EXTENT_MAN INITIAL_EXTENT ALLOCATIO
    LOCAL 65536 SYSTEM
    Results shows that SYSTEM tablespace in 9i database is locally managed.
    Where as results of below query from 11g database is indicating that users tablespace in 11g is also locally managed.
    SQL> select extent_management,initial_extent,allocation_type from dba_tablespaces where tablespace_name='USERS';
    EXTENT_MAN INITIAL_EXTENT ALLOCATIO
    LOCAL 65536 SYSTEMGood to see that you also picked up the allocation_type at the same time.
    So you have shown that the discrepancy between 9i and 11g isn't down to the difference in extent management.
    Are there any other differences between the tablespaces when you compare 9i system with non-system, and 9i system with 11g non-system ? (Hint - we have an anomaly with space allocation.)
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Author: <b><em>Oracle Core</em></b>

  • Getting the count of rows present in the oracle table

    Hi all,
    i want to get the total number of rows present in the sql table to the appmodule.
    After applying the some view criteria to the view object. if it try with getallrowsinrange it was giving count of rows present in the viewobject but i want total number of rows present in the sql table.
    How can i get that
    I am using jdev 11.1.1.5
    Thanks in advance

    I threw something together, quick and dirty, feel free to optimize.
    Assuming that you want the table count, I put the code into a EntityDefImpl subclass since this is what represents a table in the middle-tier.
    public class EmpDefImpl
          extends EntityDefImpl {
       * This is the default constructor (do not remove).
      public EmpDefImpl( ) {}
      //~ Methods ****************************************************************************
      public long getTableRowCount( DBTransaction transaction ) {
        String query = getQuery( );
        String countQuery = String.format( "SELECT COUNT(*) FROM (%s)", query );
        long count = 0;
        ViewObject vo = transaction.createViewObjectFromQueryStmt( countQuery );
        try {
          vo.executeQuery( );
          Row row = vo.first( );
          Number number = (Number)row.getAttribute( 0 );
          count = number.longValue( );
        } finally {
          vo.remove( );
        return count;
    }Depending on your type map, you might not get a oracle.jbo.domain.Number, but something else, so the cast might need correction.
    Usage example:
    public class EmpEditViewImpl extends ViewObjectImpl {
      public EmpEditViewImpl() {
      protected void executeQueryForCollection( Object object, Object[] object2, int i ) {
        super.executeQueryForCollection( object, object2, i );
        EmpDefImpl def = ( EmpDefImpl )getEntityDef( 0 );
        long tableRowCount = def.getTableRowCount( getDBTransaction() ) );
        // Do something with it
    }As you can see, the code is pretty generic. You might also be able to put this into an ADF extension base class.
    Sascha
    Edited by: Sascha Herrmann on Jun 7, 2012 2:39 PM

  • DBMS Gather Stats using ESTIMATE, gives varying number of rows

    I am a little intrigued by the gather_table_stats results for number of rows on user_tables.
    A table with no maintenance on it, has 242115 rows.
    When I gather stats COMPUTE, num_rows from user_tables = 242115.
    However, when I ESTIMATE the figure changes, without apparent reason:
    10% - 240710
    25% - 240564
    50% - 242904
    99% - 242136
    Using ESTAIMTE, I would expect the number of rows that are inspected to change, but not the resulting number of rows on User_tables!
    I wonder, why is this?
    Thanks

    Thank you for that amusing analogy!
    However, it would be interesting to know where it
    gets this idea from. Why does it decide sometimes
    more, sometimes less, what basis?Actually I'm not the person that knows the precise algorithm, I don't know also any links to docs handy that describes how it is done. But one scenario would be to enble trace and check what sql oracle is issuing to gather stats. Of course it won't be all the algorithm, but probably you'll get some insight.
    I mean, If I knew I had not removed or added any
    socks to the wardrobe or even if I was unsure anyone
    else had, I would use the previous count as my
    starting point.AFAIK Oracle doesn't have any previous knowledge i.e. to be more precise Oracle doesn't use it. Because you as a person probably know something more how the table was or wasn't changed, but Oracle doesn't know and/or use such information at least for stats gathering.
    Gints Plivna
    http://www.gplivna.eu

  • Number of rows in DB

    To know the number of rows in a table, count(*) is used.
    It is fast to get the result if you directly type the command into MYSQL, but not in servlet.
    The codes I often used look like this way:
    ResultSet resultSet =
    stmt1.executeQuery("SELECT COUNT(*) FROM CONTENT");
    resultSet.next();
    rowcount = resultSet.getInt(1);
    Please tell me if there is a better and faster way to get the same result as what the codes do above!
    Please help if you could!

    To know the number of rows in a table, count(*) is
    used.
    It is fast to get the result if you directly typethe
    command into MYSQL, but not in servlet.It will do it just as fast as MYSQL did it. If you're
    seeing a lag time it's more likely because of other
    code, such as establishing the JDBC connection as
    well. Are you using connection pools like you should?In the company i work for I once red an artical saying the using
    count(1) // or any literal in this case
    instead of count(*) is faster.
    becouse when you call count with column names or * in it the dbms fetch the values of actual column and count that row only if any of those columns has a not null value but if you are calling count(1) it does not fetch any column values just keep counting rows.
    But you do not notice any different unless you got large number of rows and columns in the table.

  • How display number of row in select statement

    How can I display number of row in select statement?
    Table
    data1 data2
    xxx ccd
    wss qwe
    qws uij
    I need get from SELECT statement:
    1 xxx ccd
    2 wss qwe
    3 qws uij

    user13734495 wrote:
    Thank you from answer.
    Statement
    select rownum rn, data1, data2 from table
    is good.
    And what have I do went I use
    select rownum rn, data1, data2 from table order by data1
    and I get
    3 qws uij
    2 wss qwe
    1 xxx ccd
    I need
    1 qws uij
    2 wss qwe
    3 xxx ccdhence the importance of describing the complete problem.
    select
      rownum,
      data1,
      data2
    from(
      select
        data1,
        data2
      from
        table
      order by
        data1)

  • Setting number of rows and columns

    How do I set the number of rows and columns of a table, say 2348 rows by 3 columns?
    Then how do I quickly select the last row?
    Also, if I enter a formula in row 1 column 2, how do I quickly copy that formula down to row 1435, or to the end of the column? Dragging seems slow and awkward.

    I wish to add a few words to Jerrold responce.
    gjf12 wrote:
    How do I set the number of rows and columns of a table, say 2348 rows by 3 columns?
    Then how do I quickly select the last row?
    Also, if I enter a formula in row 1 column 2, how do I quickly copy that formula down to row 1435, or to the end of the column? Dragging seems slow and awkward.
    The process that you describe is inefficient.
    The efficient one is :
    create a table
    enter the formulas in a single row
    delete the rows below.
    Now, each newly inserted row will contain the formulas.
    From my point of view, it's when this is done that it will be interesting to apply a script adding rows.
    Here is a script inserting rows.
    --[SCRIPT insertRows]
    Enregistrer le script en tant que Script : insertRows.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner une cellule au-dessous de laquelle vous voulez insérer des lignes.
    menu Scripts > Numbers > insertRows
    Le script vous demande le nombre de lignes désiré puit insère celles-ci.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    --=====
    Save the script as a Script: insertRows.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select a cell below which you want to insert rows.
    menu Scripts > Numbers > insertRows
    The script ask you the number of rows to insert then it does the required insertion.
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    Save this script as a … Script in the "Folder Actions Scripts" folder
    <startupVolume>:Library:Scripts:Folder Action Scripts:
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2010/01/13
    --=====
    on run
    set defaultValue to 100
    if my parleAnglais() then
    set myInteger to my askAnumber("Insert how many rows ?", defaultValue, "i")
    else
    set myInteger to my askAnumber("Combien de lignes voulez-vous insérer ?", defaultValue, "i")
    end if
    set {dName, sName, tName, rname, rowNum1, colNum1, rowNum2, colNum2} to my getSelParams()
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    repeat myInteger times
    add row below row rowNum2
    end repeat
    end tell
    end run
    --=====
    on getSelParams()
    local r_Name, t_Name, s_Name, d_Name, col_Num1, row_Num1, col_Num2, row_Num2
    set {d_Name, s_Name, t_Name, r_Name} to my getSelection()
    if r_Name is missing value then
    if my parleAnglais() then
    error "No selected cells"
    else
    error "Il n'y a pas de cellule sélectionnée !"
    end if
    end if
    set two_Names to my decoupe(r_Name, ":")
    set {row_Num1, col_Num1} to my decipher(item 1 of two_Names, d_Name, s_Name, t_Name)
    if item 2 of two_Names = item 1 of two_Names then
    set {row_Num2, col_Num2} to {row_Num1, col_Num1}
    else
    set {row_Num2, col_Num2} to my decipher(item 2 of two_Names, d_Name, s_Name, t_Name)
    end if
    return {d_Name, s_Name, t_Name, r_Name, row_Num1, col_Num1, row_Num2, col_Num2}
    end getSelParams
    --=====
    set {rowNumber, columnNumber} to my decipher(cellRef,docName,sheetName,tableName)
    apply to named row or named column !
    on decipher(n, d, s, t)
    tell application "Numbers" to tell document d to tell sheet s to tell table t to return {address of row of cell n, address of column of cell n}
    end decipher
    --=====
    set { d_Name, s_Name, t_Name, r_Name} to my getSelection()
    on getSelection()
    local _, theRange, theTable, theSheet, theDoc, errMsg, errNum
    tell application "Numbers" to tell document 1
    repeat with i from 1 to the count of sheets
    tell sheet i
    set x to the count of tables
    if x > 0 then
    repeat with y from 1 to x
    try
    (selection range of table y) as text
    on error errMsg number errNum
    set {_, theRange, _, theTable, _, theSheet, _, theDoc} to my decoupe(errMsg, quote)
    return {theDoc, theSheet, theTable, theRange}
    end try
    end repeat -- y
    end if -- x>0
    end tell -- sheet
    end repeat -- i
    end tell -- document
    return {missing value, missing value, missing value, missing value}
    end getSelection
    --=====
    on decoupe(t, d)
    local l
    set AppleScript's text item delimiters to d
    set l to text items of t
    set AppleScript's text item delimiters to ""
    return l
    end decoupe
    --=====
    Asks for an entry and checks that it is an floating number
    set myInteger to my askAnumber(Prompt, DefaultValue, "i")
    set myFloating to my askAnumber(Prompt, DefaultValue, "f")
    on askAnumber(lPrompt, lDefault, ForI)
    local lPrompt, lDefault, n
    tell application (path to frontmost application as string)
    if ForI is "f" then
    set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
    try
    set n to n as number (* try to convert the value as an number *)
    return n
    on error
    if my parleAnglais() then
    display alert "The value needs to be a floating number." & return & "Please try again."
    else
    display alert "La valeur saisie doit être un nombre décimal." & return & "Veuillez recommencer."
    end if
    end try
    else
    set n to text returned of (display dialog lPrompt default answer lDefault as text)
    try
    set n to n as integer (* try to convert the value as an integer *)
    return n
    on error
    if my parleAnglais() then
    display alert "The value needs to be an integer." & return & "Please try again."
    else
    display alert "La valeur saisie doit être un nombre entier." & return & "Veuillez recommencer."
    end if
    end try -- 1st attempt
    end if -- ForI…
    end tell -- application
    Here if the first entry was not of the wanted class
    second attempt *)
    tell application (path to frontmost application as string)
    if ForI is "f" then
    set n to text returned of (display dialog lPrompt & " (" & (1.2 as text) & ")" default answer lDefault as text)
    try
    set n to n as number (* try to convert the value as an number *)
    return n
    on error
    end try
    else
    set n to text returned of (display dialog lPrompt default answer lDefault as text)
    try
    set n to n as integer (* try to convert the value as an integer *)
    return n
    on error
    end try -- 1st attempt
    end if -- ForI…
    end tell -- application
    if my parleAnglais() then
    error "The value you entered was not numerical !" & return & "Goodbye !"
    else
    error "La valeur saisie n’est pas numérique !" & return & "Au revoir !"
    end if
    end askAnumber
    --=====
    on parleAnglais()
    local z
    try
    tell application "Numbers" to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z is not "Annuler")
    end parleAnglais
    --=====
    --[/SCRIPT]
    Yvan KOENIG (VALLAURIS, France) mercredi 13 janvier 2010 12:43:34

  • How to find accurate number of Rows, and size of all the tables of a Schema

    HI,
    How to find the accurate number of Rows, and size of all the tables of a Schema ????
    Thanks.

    SELECT t.table_name AS "Table Name",
    t.num_rows AS "Rows",
    t.avg_row_len AS "Avg Row Len",
    Trunc((t.blocks * p.value)/1024) AS "Size KB",
    t.last_analyzed AS "Last Analyzed"
    FROM dba_tables t,
    v$parameter p
    WHERE t.owner = Decode(Upper('&1'), 'ALL', t.owner, Upper('&1'))
    AND p.name = 'db_block_size'
    ORDER by 4 desc nulls last;
    ## Gather schema stats
    begin
    dbms_stats.gather_schema_stats(ownname=>'SYSLOG');
    end;
    ## Gather a particular table stats of a schema
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    http://www.oradev.com/create_statistics.jsp
    Hope this will work.
    Regards
    Asif Kabir
    -- Mark the answer as correct/helpful

Maybe you are looking for

  • HT203822 Continuing problems with Apple TV

    My AppleTv had been working very well with the airplay on my Mac for a year. For awhile doing a 'settings reset' solved the problem but lately I must connect Apple Tv to Itunes and replaced the Apple TV software. Then everything works fine for a day

  • FormatDate WebIntelligence Function Error

    Hello I have 2 date objects (start date and end date). I need to be able to replicate the DAYS360 function that is in EXCEL. I have SQL code that allows me to do this and have been able to create a number of variables in my WebIntelligence document i

  • Calling a web service reference from PL/SQL

    Hello, could anyone give me a hint how to call a web service that is defined as web service reference from a PL/SQL page process (PL/SQL anonymous block). Many thanks in advance Lukasz

  • HotSpot Server supported on NT?

    Back in February, I asked about HotSpot Server being supported on NT. I got the following response. I am not able to find this bug on Sun's site to determine if it's fixed and what version. I'm also not clear on why 4.5.1 is listed as supported with

  • Systemd (and Lennart)

    Just to clarify, as some people are apparently unclear about these topics and why they are routinely closed and marked for deletion. Discussion about systemd is perfectly acceptable; assuming that it is rational, technical and relevant to Arch. What