Record counts of the tables in USER_TABLES

Hello everyone.
Please give me advice, is it possible to enumerate the tables in the USER_TABLES and in the same time to retrieve the record count in every each of them?
To illustrate, I want something like that:
select t.table_name,(select count(*) from t.table_name) from USER_TABLES t
This is only for isllustration. I know that is not the way.
Thank you in advance for your answers.

Code could be compacted down a little...
SQL> set serveroutput on
SQL> ed
Wrote file afiedt.buf
  1  declare
  2    cursor cur_table_count is
  3      select table_name from user_tables order by table_name;
  4    v_cnt number;
  5  begin
  6    dbms_output.put_line('Table Name                     Record Count');
  7    dbms_output.put_line('============================== ============');
  8    for t in cur_table_count
  9    loop
10      execute immediate 'select count(*) from '||t.table_name into v_cnt;
11      dbms_output.put_line(RPAD(t.table_name,31)||v_cnt);
12    end loop;
13* end;
SQL> /
Table Name                     Record Count
============================== ============
BONUS                          0
DEPT                           4
EMP                            14
SALGRADE                       5
PL/SQL procedure successfully completed.

Similar Messages

  • Get records count of all tables

    Hi ,
    I am trying to get the record count of all tables using dynamic query. I don't know how to put the value in placeholder. I tried the below code.
    SET SERVEROUTPUT ON SIZE 1000000
    DECLARE
         CURSOR table_list
         IS
         select OBJECT_NAME from user_objects
         where object_type in ('TABLE')
         and object_name not like '%AUDIT_DDL%'
         AND object_name not like 'MD_%'
         AND object_name not like 'EXT_%'
         AND object_name not like 'STG_%'
         AND object_name not like 'SYS_%'
         AND object_name not like 'TMP_%'
         AND object_name not like 'TEMP_%'
         order by 1;
         v_count     NUMBER :=0;
         query_str VARCHAR2(1000);
    BEGIN
         FOR table_name IN table_list
         LOOP
              query_str :='SELECT COUNT(1) FROM  ' || table_name.OBJECT_NAME;
    dbms_output.put_line(query_str);
              dbms_output.put_line('Table Name:' || table_name.OBJECT_NAME );
              v_count:= execute immediate query_str;
              dbms_output.put_line('Table Name:' || table_name.OBJECT_NAME || ', Count ' || v_count );
         END LOOP;
    END;
    I know I am doing wrong in the bold lines. But not sure how to fix it. Please help. Thanks in advance.

    Hi,
    Welcome to the forum!
    What you posted is basically right, assuming you really want to do dynamic SQL t all.
    The only problem with
    961618 wrote:
              query_str :='SELECT COUNT(1) FROM  ' || table_name.OBJECT_NAME; would be if the object name included special characters (such as single-quotes) or lower-case letters. To avoid any possible problems, I would put the object name inside double-quotes:
    ...     query_str := 'SELECT COUNT (*) FROM "' || table_name.OBJECT_NAME
                                               || '"';
              v_count:= execute immediate query_str;
    The correct syntax is
    execute immediate query_str INTO v_count;V_count will be the number of rows in a single table. Keep another variable (say total_v_count) that keeps the total count so far.
    Do you really need dynamic SQL?
    SELECT     SUM (num_rows)     AS total_rows
    FROM     user_tables
    WHERE     table_name     NOT_LIKE '%AUDIT_DDL%
    AND     ...
    ;gets the same information, accurate as of the last time statistics were gathered, and some of the numbers may be approximate. Depending on how you use the results, that may be good enough for you. If you actually have 10,000,123 rows, and the query says you have 10,000,000, does it really matter?

  • Record count in internal table

    i want to know record count for the records stored in
    internal table.
    do we have any system field to display record count?

    Hi,
    Try this:
    Data: count_lines type i.
    describe table my_table lines count_lines.
    Regards,
    Arjan

  • Record selected in the table control

    Hi All,
      How do i know the line no of the record selected in the table control.I have declared a table control CONTROLS : t_control1 type tableview using screen 200.But in t_control1-current_line the line no that is stored is always 1.
    Thanks,
    Rakesh.

    in table control property window you have to set that suppose you have set itab-mark as the sel field then it will always be X if you select the field ...
    regards
    shiba dutta

  • ALV list with count of the table

    Dear all,
    My requirement is i want display the output as alv list along with the count of the table .
    i got the count  but unable to diplay the  below the list.
    please suggest me.
    Thanks& Regards,
    RP

    If you are using a custom control on the screen and then a custom container you can easily do this.
    Create a screen(Size 200 x 240), place a custom control on the screen and make it to the max size  200 x 240. Now in the attributes of the custom control, check the Resizing option for both horizontal and vertical, with some minimum numbers there.
    Now, your ALV grid automatically occupies all the space available on the screen irrespective of the size if the screen and you will have only one scroll bar.
    Regards,
    Ravi
    Note - Please mark all the helpful answers

  • How to maintain previous and record count in audit table in SQL Server 2008 r2?

    Hi Experts ,
     Situation :
    in our database we are having few of stored procedures which will drop and recreates the tables and it is scheduled on weekly basis. when this job will run all the stored procedures will drop all the tables and recreate. Now we need to create one table which
    will maintain history of the records.
    my table structure is listed below
    TableName CurrentReocrdCount CurrentExecutionDate PreviousReordCount PreviousExurtiondate
    TEST         1000                   2014-03-30            NULL        NULL
    Test         1500                   2014-04-10            1000      2014-03-30
    Test         2000                   2014-04-11            1500      2014-04-10 
    How do i achive this . 
    franklinsentil

    You need to create audit tables for these. The table will be populated by COUNT value inside stored procedure. Each time it clears the main table and fills new data and also logs count details to audit tables. You can use COUNT(*)  to get count value
    and GETDATE function to get current execution value.
    So proc will look like
    CREATE PROC procname
    @param....
    AS
    --step to drop existing table
    IF OBJECT_ID('tablename') IS NOT NULL
    DROP TABLE <table name>
    --step to fill new table
    SELECT ...
    INTO TableName
    FROM
    --Audit table fill step
    INSERT AuditTable (TableName,CurrentRecordCount,CurrentExecdate,PrevRecordCount,PrevExecDate)
    SELECT TOP 1 'TableName',(SELECT COUNT(*) FROM tableName),GETDATE(),CurrentRecordCount,CurrentExecDate
    FROM AuditTable
    ORDER BY CurrentExecDate DESC
    UNION ALL
    SELECT 'TableName',(SELECT COUNT(*) FROM tableName),NULL,NULL
    WHERE NOT EXISTS (SELECT 1 FROM AuditTable)
    GO
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to determine the cursor record count before the "open cursor"?

    Is it possible to determine the record count of an explicit cursor without running a count()? Say, my cursor definition is something like this,
    CURSOR cur_vehicle
    IS
    SELECT os.order_id, os.order_item, vs.part_id
    vs.part_num,
    vs.iso_num,
    vs.model_yr
    vs.dealer_cde,
    vs.cust_cde,
    px.plant_cd
    FROM parts_source vs,
    orders_source os,
    plant_tbl_crossref px
    wHERE os.order_id = vs.order_id
    AND vs.part_id = os.part_id
    AND vs.plant_cde = px.plant_cde
    ORDER BY os.order_id;
    I want to log the count of records returned by the above cursor prior to the first fetch, without running a count(1) for the query in cursor select.
    I know adding " Count(1) over(order by null) " in the cursor SELECT will bring it. But that does not help me log the record count to some log file or table before opening the cursor for processing.
    To conclude, my objective is to update the record count of cursor in some table before processing

    sarvan wrote:
    Is it possible to determine the record count of an explicit cursor without running a count()?
    ..snipped..No. The only way to do it correctly is inside that select.
    Each select is a consistent read. Which means that if this is done as 2 select statements, the 1st select can see a different version of the data than the 2nd select statement. does. So if you want a count and that to be consistent and on the same version of the data than the select, it has to be done as part of the select.
    Also consider what a cursor is. It is not a result set of sorts that is created in memory upfront - with a convenient interface that tells you the size/number of rows of that result set.
    A cursor is basically a program that reads database data as input and produce output. A fetch from a cursor is an instruction for this program to execute and output data.
    There's no data set that is created by the cursor from which the count can be determined. The cursor program does have state variables - like +%RowCount+ that specifies how many rows the cursor has thus far output. And you need to run that cursor to the end (no more output) in order to determine the total number of rows output by the cursor.

  • File to Jdbc: how to get record count from DB table

    Hello,
    i have a scenario file to JDBC....ihave to insert input file data to DB table.
    now my requirement is ..if i insert a file with 50 records to db table on first time, and then next time if i insert the file with 100 records to db table....the count should start from 51 in db table.
    if i insert another file 3rd time, with 25 records, the count shold start from 151...so how can i achieve this functionality....
    i think following options:
    1. in mapping write lookup to call JDBC sender channel and fetch count and map same to target filed of DB. if this is ok...please provide UDF code..2. db triggers (not suitable for my req.)
    So kindly let meknow possible solutions and required UDF codes..please
    Thanks in advance...SARAN

    >>>..if i insert a file with 50 records to db table on first time, and then next time if i insert the file with 100 records to db table....the count should start from 51 in db table.
    if i insert another file 3rd time, with 25 records, the count shold start from 151...so how can i achieve this functionality....
    i think following options:
    Suggestions:
    1)Create an id column in db table.  Talk to DB guy to create oracle sequencer for that column. So, every time you insert record that field will be updated with oracle sequencer. You dont need to handle this.
    Refer this link
    http://www.techonthenet.com/oracle/sequences.php
    2) If you want to handle via pi,  following suggestions..
    If you use PI 7.1 or above, use jdbc lookup in the mapping and do the query  something like this
    Refer this link
    /people/jin.shin/blog/2008/02/15/sap-pi-71-mapping-enhancements-series-graphical-support-for-jdbc-and-rfc-lookups
    Do select query as below
    select count(*) from tablename;
    the above query will return number of rows exist in the table. So use that value and map it in the target field.
    If you use pi 7.0 or below then use the previous reply and do the UDF implementation for jdbc lookup during mapping. Because jdbc lookup does not support in those versions.
    Hope that helps.
    Baskar

  • Query to display all records count of all tables in a schema

    Hi,
    I need to count all the records of all my tables in a certain schema and display the max amount of the record count. Do you have a script for this one??

    SQL> create function countrec(in_tab in varchar2) return number is
      2  retval number;
      3  begin
      4    execute immediate 'select count(*) from '||in_tab into retval;
      5    return retval;
      6  end;
      7  /
    Function created.
    SQL> select table_name, countrec(table_name)
      2  from tabs;
    TABLE_NAME                     COUNTREC(TABLE_NAME)
    QUERY_TOOL_DATA_COLLECTION                        5
    TEST01                                            0
    T1                                               14
    EMP                                              14
    SALGRADE                                          5
    FILES                                             0
    PROVA                                             0
    TEST                                              0
    T_MASTER                                          1
    T_CHILD                                           3
    TAB_ONE                                          30
    TAB_TWO                                          10
    A                                                 3
    B                                                 4
    C                                                 3
    D                                                 3
    BONUS                                             0
    DEPT                                              4
    18 rows selected.Max

  • How to compare record count of two tables?

    Hi,
    i am in need of simple sql script where i can compare two table record count.
    i have something like below:
    (select count(*) from table1) minus (select count(*) from table2)
    now the problem is if the table1 count greater then table2 count the output is fine.
    If the table2 record count is more then i am getting zero as the output.
    how can i get the difference in two tables record count?
    Thanks a lot in advance.
    --Raman.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Doing a MINUS between the counts does not yield the diff.
    e.g. if table A has 100 records and table B has 70 records then,
    SELECT count(*) FROM A
    minus
    SELECT count(*) from B
    will give 100 and not 30.
    Try this:
    SELECT (
    CASE WHEN ((select count(*) cnt from A) - (select count(*) cnt from B)) <0
    THEN ((select count(*) cnt from A) - (select count(*) cnt from B))* -1
    ELSE ((select count(*) cnt from A) - (select count(*) cnt from B)) END) Difference
    FROM dualor this is simpler
    SELECT abs(((select count(*) cnt from A) - (select count(*) cnt from B))) difference FROM dualEdited by: Caitanya on Jan 9, 2009 7:12 AM
    Applied abs function after seeing BluShadow's post :)

  • How to get the total record count for the report

    Hi,
    How can I get count of the total records shown in the report. When we set the report attributes, we have an option "Set Pagination from X to Y of Z"
    Does anyone know how can I get the Z value from APEX variables.
    I know we can use that query and get the count but I just want to know how we can use APEX Variables effectively.
    Thanks in advance.

    You write a loop, something like this:
    Go_block('B1');
    If not form_success then
      Raise Form_Trigger_failure;
    End if;
    First_Record;
    If not form_success then
      Raise Form_Trigger_failure;
    End if;
    Loop
      If :system.record_status in('CHANGED','INSERT') then
        -- modify the record here--
      End if;
      Exit when :System.Last_Record = 'TRUE';
      Next_Record;
    End Loop;
    First_Record;But be very careful-- If your block can fetch a large number of rows, (over 100), this loop can take a long time, and you should not use this method. The loop will continue fetching more rows from the database until all rows satisfying the query are retrieved.

  • No record found in the table while using condition for the new added field

    Hi,
    I have added a new field in Z table. There is lots of record in the table. The field which I added have null records. When I am checking the record using the condition new field equal(EQ) to space or blank. This shows no record in the table, but when I execute whole of the table, it shows entries for all field.
    Please suggest. Thanks in Advance.
    Rgds,
    Hemant Maurya

    Hi Suhas,
    Thanks for your quick response.
    Yes I have run SE14 and activate & adjust the database, But problem is same.
    My select query is:
    SELECT VBELN
             PI
             GJAHR
             KUNNR
             GPD
             GPI
    INTO TABLE I_GP_DATA
    FROM ZFI_GP_DISCOUNTS
    WHERE AUGDT BETWEEN ZFI_GP_DISCOUNTS-AUGDT AND ZFI_GP_DISCOUNTS-P_DATE
    AND DOC_NO EQ SPACE.
    Thanks & Regards,
    Hemant Maurya

  • Filtering records with in the table

    Hi All,
    Table:Res
    manager | lead | cuid
    yyy | xxx | 111
    zzz | yyy | 222
    axc zzz 999
    in the above table cuid's of xxx and yyy is 111 and 222 like tht i've n no of records in the table.
    here i want to retrive the lead and manager cuid's by giving the lead cuid.
    i.e for example i want to retrive xxx and yyy cuid's by entering xxx cuid.
    can any one give me the query for the above problem.
    Thanks in Advance

    This?
    SQL> create table res
      2  as
      3  select 'yyy' manager, 'xxx' lead, 111 cuid from dual union all
      4  select 'zzz', 'yyy', 222 from dual union all
      5  select 'axc', 'zzz', 999 from dual
      6  /
    Tabel is aangemaakt.
    SQL> var P_CUID number
    SQL> exec :P_CUID := 111
    PL/SQL-procedure is geslaagd.
    SQL> select :P_CUID lead_cuid
      2       , r2.cuid manager_cuid
      3    from res r1
      4       , res r2
      5   where r1.manager = r2.lead
      6     and r1.cuid = :P_CUID
      7  /
                                 LEAD_CUID                           MANAGER_CUID
                                       111                                    222
    1 rij is geselecteerd.Regards,
    Rob.

  • How do we capture the record selected in the table control?

    Hi,
      In the table control when the user selects a record we need to capture that record and pass it to the next screen.how can we do this?
    Thanks,
    Rakesh.

    Hello
    First of all you need a 'mark' column in your TC structure.This should be char1.
    This column has to be put into the TC Attributes as mark column.
    Then to get back the info from the TC go the following way:
    PAI
    loop at <fs_it> .               "Field symbol of your table.
        MODIFY <fs_it> FROM wa_basic
        INDEX tc_maintenance-current_line.
    endloop.
    Message was edited by:
            Werner Gerbert

  • How to implement the record count on the page

    Dear,
    I have a basic search page, results region with a simple table.
    I need to show the total number of records returned by a search query.
    Suppose I create messageStyledText "counter" bean to show the result.
    The result will be calculated in the ProcessFormRequest, how would I set the value of the the "counter" bean then? I can not do that in PFR.
    Thank you
    Anatoliy

    In the PFR method of controller, get the row count of VO when user click on search button and then set its value in the counter bean.
    Here the dummy code.. check syntax error & other compile time error
    if(pageContext.getParameter("SearchBtn") != null)
    OAViewObject vo = (OAViewObject)am.findViewObject("SearchVO1")
    if (vo!= null)
    String fetchedRowCount = vo.getFetchedRowCount();
    OAMessageStyleTextBean msb = (OAMessageStyleTextBean)webBean.findChildRecursive("CounterBean");
    if(msb != null)
    msb.setvalue(pageContext, fetchedRowCount);
    }Thanks
    --Anil
    http://oracleanil.blogspot.com

Maybe you are looking for

  • Process Chain takes alonf time to run

    Hello All, We have a process chain which loads data for texts, attributes etc. On certain days the process chain will run extremely fast and maybe take a couple of hours, other days the same process chain may take 24 hours to run.  It appears to get

  • Variable creation for Transaction S_ALR_87013336

    Hi I am getting following error on executing the transaction S_ALR_87013336 Global variable & has been deleted Message no. KH488 Diagnosis Global variable & has been deleted. Procedure Modify the report or form so that it no longer uses global variab

  • How to create a new schema ?

    Hi, Can someone tell me how to create a new schema please ? What i need as user & rights ? Thanks

  • Not converting anything but get error: "Conversion failed converting varchar value 'X' to data type int"

    I have created the following trigger that fires instead of an UPDATE statement and copies the altered data over to an Audit table before proceeding with the requested UPDATE. After doing so, I wrote a simple UPDATE statement for testing: UPDATE Produ

  • Premiere Elements 11 is here!

    The latest version of the Elements suite of programs is here! For information on the latest features in Premiere Elements, see our FAQs to the right of this forum. http://forums.adobe.com/thread/1071693