Count number of rows in a table

Hi,
I have a requirement. I want to frame a SQL, which takes schema name as input and returns tables owned by that schema and number of rows inside a particular table.
A Sample output:
===========
Table            No. of Rows
~~~~          ~~~~~~~~
A                    123
B                    126
C                    234
.Can somebody help me in framing a query for the same.
Regards,

hoek wrote:
But you could use this script:
http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html
Laurent's solution most likely was published before IOT. Anyway, IOT ovwerflow tables must be excluded. Otherwise:
SQL> select  table_name,
  2          to_number(
  3                    extractvalue(
  4                                 xmltype(
  5                                         dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)),'/ROWSET/ROW/C')) cou
  6    from  dba_tables
  7    where owner = 'OE'
  8  /
ERROR:
ORA-19202: Error occurred in XML processing
ORA-25191: cannot reference overflow table of an index-organized table
ORA-06512: at "SYS.DBMS_XMLGEN", line 176
ORA-06512: at line 1
no rows selected
SQL> select  table_name,
  2          to_number(
  3                    extractvalue(
  4                                 xmltype(
  5                                         dbms_xmlgen.getxml('select count(*) c from '||owner || '.' || table_name)),'/ROWSET/ROW/C')) count
  6    from  dba_tables
  7    where owner = 'OE'
  8      and nvl(iot_type,'X') != 'IOT_OVERFLOW'
  9  /
TABLE_NAME                          COUNT
CUSTOMERS                             319
WAREHOUSES                              9
ORDER_ITEMS                           665
ORDERS                                105
INVENTORIES                          1112
PRODUCT_INFORMATION                   288
PRODUCT_DESCRIPTIONS                 8640
PROMOTIONS                              2
PRODUCT_REF_LIST_NESTEDTAB            288
SUBCATEGORY_REF_LIST_NESTEDTAB         21
10 rows selected.
SQL>  SY.

Similar Messages

  • Count number of rows in table

    Hi!
    1. How can you through ABAP and select statements count the number of rows in one table?
    2. I want to read all rows from one table to an internal table. Can this be done dynamically or do I first have to count the number of rows in the table and then declare an internal table with the number of rows counted.
    regards
    Baran

    HI,
    No you don't have to count number of rows first, Internal table size will increase dynamically. you have to declare this with initial size like this.
    <b>data: itab type standard table of bkpf initial size 0.
    SELECT * FROM bkpf into table itab.</b>
    All values from bkpf will be inserted into table internal table itab.
    Regards,

  • How to add the Row count(number of rows in table)  in  the table header?

    Hi,
    I'm having a table. This table is viewed when i click on a search button.
    <b>On the table header it should dynamically display the number of rows in the table, i.e., the row count.</b>
    How to do this? could any one explain me with the detailed procedure to achieve this.
    Thanks & Regards,
    Suresh

    If you want to show a localized text in the table header, you should use the <b>Message Pool</b> to create a (parameterized) message "tableHeaderText" like "There are table entries".
    Next, create a context attribute "tableHeaderText" of type "string" and bind the "text" property of the table header Caption UI element to this attribute.
    Whenever the table data has changed (e.g. at the end of the supply function for the table's data source node), update the header text:
    int numRows = wdContext.node<TableDataSourceNode>().size();
    String text = wdComponentAPI.getTextAccessor().getText
      IMessage<ComponentName>.TABLE_HEADER_TEXT,
      new Object[] { String.valueOf(numRows) }
    wdContext.currentContextElement().setTableHeaderText(text);
    Maybe you want to provide a separate message for the case that there are no entries.
    Alternatively, you can make the attribute calculated and return the header text in the attribute getter.
    Armin

  • How to count number of rows in table

    can I get number of row in table except Count(*) in pl/sql
    is there any other way

    Also posted and answered here
    how to count number of rows in table
    count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless.

  • How to find number of rows in a table

    i have one table ,it contains millions of record,how can i know number of rows in that table without using count(*),
    i tried in user_table ,for the column NUM_ROWS,but it is not showing number of rows,pls send me a solution for this.
    regards,
    singh

    Ok, that only was to show simply that max option
    might not an option to reduce execution time.Yes, but I/O variances have a tendency to really skew the observed elapsed execution time - making execution time alone a poor choice to determine what SQL will perform better than another.
    Both MAX(ROWNUM) and COUNT(*) results in the same amount of I/O - as both uses the exact same execution plan, I/O wise. In this example, a FTS.
    SQL> create table testtab nologging as select * from all_objects where rownum < 10001;
    Table created.
    -- warmed up the buffer cache with a couple of SELECTs against TESTAB in order
    -- to discard PIOs from the results
    SQL> set autotrace on
    SQL> select count(*) from testtab;
    COUNT(*)
    10000
    Execution Plan
    Plan hash value: 2656308840
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 35 (9)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | | |
    | 2 | TABLE ACCESS FULL| TESTTAB | 9262 | 35 (9)| 00:00:01 |
    Note
    - dynamic sampling used for this statement
    Statistics
    0 recursive calls
    0 db block gets
    131 consistent gets
    0 physical reads
    0 redo size
    223 bytes sent via SQL*Net to client
    238 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    SQL> select max(rownum) from testtab;
    MAX(ROWNUM)
    10000
    Execution Plan
    Plan hash value: 2387991791
    | Id | Operation | Name | Rows | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 35 (9)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | | |
    | 2 | COUNT | | | | |
    | 3 | TABLE ACCESS FULL| TESTTAB | 9262 | 35 (9)| 00:00:01 |
    Note
    - dynamic sampling used for this statement
    Statistics
    0 recursive calls
    0 db block gets
    131 consistent gets
    0 physical reads
    0 redo size
    225 bytes sent via SQL*Net to client
    238 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    So seeing that we have the exact same baseline for both queries, and that PIO does not influence the results, we time a 1000 executions of both.
    SQL> declare
    2 cnt number;
    3 begin
    4 for i in 1..1000
    5 loop
    6 select count(*) into cnt from testtab;
    7 end loop;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.19
    SQL>
    SQL> declare
    2 cnt number;
    3 begin
    4 for i in 1..1000
    5 loop
    6 select max(rownum) into cnt from testtab;
    7 end loop;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:15.87
    SQL>
    This shows that what makes the MAX() more expensive is just that - determining the MAX(). For each row, Oracle has to call its internal MAX() function with two values - the current max result and the new value. This function then returns the new max value. This overhead per row adds up to a significant overhead in execution time - making the MAX() approach 5x slower than the COUNT() approach.

  • Number of rows in each table

    Hi
    How to find the number of rows in each table of a database by just using a SQL query,
    and should not use the data dictionary tables also... is there any way...??
    Thanks
    MJ

    It can be done in a single SQL like ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>SELECT table_name,
      2         DBMS_XMLGEN.getxmltype ('SELECT Count(*) c FROM ' || table_name).EXTRACT ('//text()').ge
    tnumberval() tot_rows
      3  FROM user_tables;
    TABLE_NAME                       TOT_ROWS
    QUESTIONTYPE                            0
    SRGROUPTABLE                            1
    ST_TEST                                 4
    REGISTER                                0
    DEB_1                                   2
    EMP1                                    0
    6 rows selected.
    Elapsed: 00:00:12.04Credit goes to Michael. ;)
    Regards.
    Satyaki De.

  • Count number of rows

    is there a more elegant way to count the number of rows in a table. Only way I can think is to make a hidden column populated with the row numbers and then use a max function.
    thanks

    Thanks Yven - just the ticket.
    PW your suggestion was useful as I didnt know about the COUNTA function.
    I have a table that takes all it values via an Index calculation from a master table (selected by a check mark or number). As such it is possible to have more selected in the master list than rows are available in the View table. I can now add a warning that tells me more values have been selected than can be presented.
    I actually have four tables each representing a song set list for a performance and the master table is the complete list of songs to choose from. The reality is the size of the table isnt likely to change so I probably could use a fixed value but I always like to be flexible.
    The system works OK as I can drag the songs into different orders but gets a little messed up if I change the sort order of the master or add new entries. and if I decide a song needs to be in another set I have to go back to the master to change the cat code.
    I often think this would be a good idea for a piece of software especially when touch pads and screen become more popular. There is a nice little list software that demoed the iPhone capabilites in this idea.

  • Counting all the rows in a table

    I've just come across what I think is a big oversight in the Power Query UI: it doesn't seem to be possible to find the total number of rows in a table using just the functionality available in the UI. I can do this very easily if I write my own expression
    using Table.RowCount(), but I would have expected to be able to do this through the UI. At the moment, when I go to the Group By dialog (which is where I'd expect to be able to do this) and delete all the columns in the Group By section the OK button gets
    greyed out. 
    Am I missing something here?
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy and run
    public SQL Server and BI training courses in the UK

    Hi Miguel,
    No, what I was talking about was to be able to use the Group By dialog and have no column to group by - that's to say, I'd just want to be able to count the number of rows in a table (or return the sum of all values in a column, or the min/max etc) and return
    a single value. I know I could do this by inserting an artificial column that only contains one distinct value, and using that in the Group By, or by writing my own expression that uses Table.RowCount(), but it seems like a very basic operation that should
    be easier to do in the UI.
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy
    and run public SQL Server and BI training courses in the UK

  • How to retrieve number of rows of a table by jdbc?

    can anyone show me a simple snippet of a java code about how to retrieve the number of ROWS in a table?
    or even only showing the jdbc command that does this job would be enough.
    thanks in advance :)
    cheers

    1. query for the count, then execute the query
    "select count(*) from test" then
    "select * from test"
    2. create a scrollable ResultSet then
    rs.last();
    int count = rs.getRow();
    rs.beforeFirst();
    Jamie
    p.s. this topic has been discussed MANY times. Do a search on this forum and you will get lots of other discussions on this topic.

  • Displayin message and fixing the number of rows in a table

    Hi Experts,
    I have a requirement like this
    there is a table, where i need to diplay a message when there are no records and no rows should be visible on that table.
    Also, when the records are populated from the context, i need to fix the number of rows in that table and display the records.
    Please let me know hw this can be achieved.
    Also in the table I have Link to URL, please let me know how to handle this reference, when i set the reference Property, its giving me an error stating that the file doesn't exist when the table gets loaded.
    Thanks in Advance
    Regards,
    Palani

    Hi
    Oh!!  You should to  explain it at first thread itself that you want to display a JPG imange or other WDWebResourceTypetaken form the backend.
    1. So this is not at all a URL
    2. You have to convert binary data to WDWebResource then display it in either Image UI element or other (like PDF , txt etc)
    3
    try
                   //        Read the datasource of the FileUpload
                   IWDResource res = wdContext.currentContextElement().getResource();
                   InputStream in = res.read(false);
                   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                   int length;
                   byte[] part = new byte[10 * 1024];
                   while ((length = in.read(part)) != -1)
                        bOut.write(part, 0, length);
                   in.close();
                   bOut.close();
                   IPrivateUploadCompView.IImageTableElement ele = wdContext.nodeImageTable().createImageTableElement();
                   ele.setImage(wdContext.currentContextElement().getResource().getUrl(0));
                   ele.setText(res.getResourceName());
                   wdContext.nodeImageTable().addElement(ele);
              catch (Exception e)
                   wdComponentAPI.getMessageManager().reportWarning(e.toString());
    Here I assume that you convert that data to IWDResource type or
    4.
    WDWebResource.getWebResource(wdContext.currentContextElement().getresource(), type);
    // getResource of type binary which u read from BAPI and set it in local context , type is MIMETYPE or hardcode it as "JPG"
    5. Further help
       [Help1|To Displayan Image in Webdynpro Java from Standard Function Module;
    [Help2|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumentstobeusedinWeb+Dynpro]
    [Help3|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumenttobeusedinWeb+DynPro]
    It might code look strange at first , please do some reserch in SDN ,I did my best at this level.
    Best Regards
    Satish Kumar

  • I want a count of distinct rows in a table

    I want a count of distinct rows in a table through a single query -- is it possible?
    eg.
    table-
    create table ch1 (a int, b int, c int, d int)
    insert ch1 values (1,1,1,1)
    insert ch1 values (2,2,2,2)
    insert ch1 values (1,1,1,1)
    insert ch1 values (2,2,2,2)
    insert ch1 values (1,3,4,5)

    hi,
    create table ch1 (a int, b int, c int, d int) ;
    insert into  ch1 values (1,1,1,1);
    insert into  ch1 values (2,2,2,2);
    insert  into  ch1 values (1,1,1,1);
    insert into  ch1 values (2,2,2,2);
    insert into  ch1 values (1,3,4,5);
    SQL> select * from ch1;
             A          B          C          D
             1          1          1          1
             2          2          2          2
             1          1          1          1
             2          2          2          2
             1          3          4          5
    SQL> select distinct * from ch1;
             A          B          C          D
             1          1          1          1
             1          3          4          5
             2          2          2          2
    SQL>
      1* select count(*) from( select distinct * from ch1)
    SQL> /
      COUNT(*)
             3
    SQL> ed
    Wrote file afiedt.buf
      1   select count(*) from (select a,b,c,d  from ch1
      2* group by a,b,c,d)
    SQL> /
      COUNT(*)
             3
    SQL> Thanks,
    P Prakash

  • Need help to count number of rows and display in file

    Hello,
    my scenario is IDOC to File......i am using XSLT mapping and using FCC parameters to convert the flat file.
    now new requirement is i need to count number of rows and add count value last of the file.
    Please let me know how to do it,
    thanks in advance for your help.
    Regards,
    Chinna

    thanks again, one more Q.
    in XSLT mapping i have written for loop for complete structure.
    example : <Details>
                         <node1>
                         <node2>
                   </details>
    in XSLT mapping
                         <xsl:for-each select="ZMATMAS_01/IDOC/E1MARAM">
         <Details>
         </Details>
         </xsl:for-each>
    if i add the field at target side....then i will come under details node and it will be repeated.
    how to declare in XSLT mapping.

  • Fixed number of rows in ADF table

    Can we specify fixed number of rows for ADF table so even no rows displayed it will still show 10 empty rows.

    the rangesize property determines how many rows will be displayed and controls paging. If there are no rows to begin with (if I understand the question correctly) rangesize won't have any effect.

  • Determine Number of  rows in Internal Table

    Hi,
      I have defined my internal table as follows:
         TYPES : BEGIN OF ABC_KEY,
                  FIELD1(2)   TYPE C,
                  FIELD2(1)   TYPE C,
                  FIELD3(8)   TYPE N,
                  END OF ABC_KEY.
    DATA: itab1 TYPE TABLE OF ABC_KEY
                      WITH KEY FIELD1,
           wa_lines_1 LIKE LINE OF itab1.
    How can I retrieve the number of rows in Internal Table?
    Thanks.
    Regards,
    bw_newbie

    You can define the number of rows of the internal table using the DESCRIBE itab command .
    As the rest have already stated a sample code snippet .
    For more info type in DESCRIBE in your prgram and click on (F1) by placing the cursor on DESCRIBE .
    You will find more options as to how you can use the DESCRIBE command according to your requirement .
    Thanks ,
    Hari

  • What is the maximum number of row for a table control in LabWindows/CVI ?

    I use LabWindows CVI 8.5.1 (MMI first developped in version 6.0).
    In one of our many MMI, a table control contains a list of aircraft parameters.
    We can add as many parameters (row) as we want but over 40 000 we observe a crash of the LabWindows CVI runtime.
    Our client want to inscrease the number of parameters (row) up to 200 000 !!!
    So my questions are:
    What is the real maximum number of row for the table control ?
    Is this maximum number of row different on LabWindows 2010 version ?
    Or is there an other solution ?
    Thanks

    Greetings,
    Can you clarify what you mean by "crash"? Is there an error message thrown? Is it possible that you've consumed all of the available memory?
    Please let me know.
    Thanks, James Duvall
    Product Support Engineer
    National Instruments

Maybe you are looking for

  • Run SAP PI Interfaces 24X7. How

    How I can run PI Interfaces 24X7 to achieve Business Continuity. The solution provided as u2013      Install Separate additional PI System u2013 called as Federation PI. Is this solution really applicable? Details: 1.     Our Current Production Lands

  • Built in flashlight

    Hey everyone. I just wanted to make sure everyone knows about the built in flashlight for the 8900. Its actually the video camera light which uses the camera flash. It can be turned on by going to video camera, hitting options and selecting video lig

  • Will Diablo 2 work in bootcamp or parallels with the Intel GMA X3100?

    I have the Intel GMA X3100 graphics card on my new macbook which seems to be incompatible with Diablo 2. Usually you have to install a beta copy to run it, which is incompatible with Battle.net. If I install parallels or boot camp, will I be able to

  • Bug: Customizing Convergence banner for a specific domain does not work

    Hi, I'm trying to customize the banner for a specific domain, I was following the steps from the documentation but I found that there is a bug relate: Bug #6749263 And I tried to find if the bug was already resolved in convergence 1.0-7.01 and the se

  • How do I get caption under landscape

    How do I get a caption under a photo in landscape orientation?  The "click here for caption" only appears in portrait orientation.