How to take the count (*) corresponding to each table in a schema

Hi all

could someone please tell me, how can I take the count (*) for all the tables in a schema with the name of the corresponding table.
I want to choose the table table_name from user_tables and number of rows in the table.

Thank you
Afonso

Try the following script which should run as the owner of the schema:

SET SERVEROUTPUT ON
DECLARE
  t VARCHAR2(30);
  stmt varchar2(100);
  cnt number;
BEGIN
  FOR t IN
  (SELECT table_name FROM user_tables)
  LOOP
    stmt :='select count(*) from ' || t.table_name;
   execute immediate stmt into cnt ;
   dbms_output.put_line(t.table_name || ': ' || cnt || ' rows');
   commit;
  END LOOP;
END;
/
show errors

Tags: Database

Similar Questions

  • How to find the child level for each table in a relational model?

    Earthlings,

    I need your help, and I know that, "Yes, we can change." Change this thread to a question answered.

    So: How to find the child level for each table in a relational model?

    I have a database of relacional (9.2), all right?
    .
         O /* This is a child who makes N references to each of the follow N parent tables (here: three), and so on. */
        /↑\ Fks
       O"O O" <-- level 2 for first table (circle)
      /↑\ Fks
    "o"o"o" <-- level 1 for middle table (circle)
       ↑ Fk
      "º"
    Tips:
    -Each circle represents a table;
    -Red no tables have foreign key
    -the picture on the front line of tree, for example, a level 3, but when 3 becomes N? How is N? That is the question.

    I started to think about the following:

    First of all, I need to know how to take the kids:
    select distinct child.table_name child
      from all_cons_columns father
      join all_cons_columns child
     using (owner, position)
      join (select child.owner,
                   child.constraint_name fk,
                   child.table_name child,
                   child.r_constraint_name pk,
                   father.table_name father
              from all_constraints father, all_constraints child
             where child.r_owner = father.owner
               and child.r_constraint_name = father.constraint_name
               and father.constraint_type in ('P', 'U')
               and child.constraint_type = 'R'
               and child.owner = 'OWNER') aux
     using (owner)
     where child.constraint_name = aux.fk
       and child.table_name = aux.child
       and father.constraint_name = aux.pk
       and father.table_name = aux.father;
    Thought...
    We will share!

    Thanks in advance,
    Philips

    Published by: BluShadow on April 1st, 2011 15:08
    formatting of code and hierarchy for readbility

    Have you looked to see if there is a cycle in the graph of dependence? Is there a table that has a foreign key to B and B has a back of A foreign key?

    SQL> create table my_emp (
      2    emp_id number primary key,
      3    emp_name varchar2(10),
      4    manager_id number
      5  );
    
    Table created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  create table my_mgr (
      2    manager_id number primary key,
      3    employee_id number references my_emp( emp_id ),
      4    purchasing_authority number
      5* )
    SQL> /
    
    Table created.
    
    SQL> alter table my_emp
      2    add constraint fk_emp_mgr foreign key( manager_id )
      3         references my_mgr( manager_id );
    
    Table altered.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by prior child_table_name = parent_table_name
    SQL> /
    ERROR:
    ORA-01436: CONNECT BY loop in user data
    

    If you have a cycle, you have some problems.

    (1) it is a NOCYCLE keyword does not cause the error, but that probably requires an Oracle version which is not so far off support. I don't think it was available at the time 9.2 but I don't have anything old enough to test on

    SQL> ed
    Wrote file afiedt.buf
    
      1   select level lvl,
      2          child_table_name,
      3          sys_connect_by_path( child_table_name, '/' ) path
      4     from (select parent.table_name      parent_table_name,
      5                  parent.constraint_name parent_constraint_name,
      6                  child.table_name        child_table_name,
      7                  child.constraint_name   child_constraint_name
      8             from user_constraints parent,
      9                  user_constraints child
     10            where child.constraint_type = 'R'
     11              and parent.constraint_type = 'P'
     12              and child.r_constraint_name = parent.constraint_name
     13           union all
     14           select null,
     15                  null,
     16                  table_name,
     17                  constraint_name
     18             from user_constraints
     19            where constraint_type = 'P')
     20    start with child_table_name = 'MY_EMP'
     21*  connect by nocycle prior child_table_name = parent_table_name
    SQL> /
    
           LVL CHILD_TABLE_NAME               PATH
    ---------- ------------------------------ --------------------
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
             1 MY_EMP                         /MY_EMP
             2 MY_MGR                         /MY_EMP/MY_MGR
    

    (2) If you try to write on a table and all of its constraints in a file and do it in a valid order, the entire solution is probably wrong. It is impossible, for example, to generate the DDL for MY_EMP and MY_DEPT such as all instructions for a table come first, and all the instructions for the other are generated second. So even if NOCYCLE to avoid the error, you would end up with an invalid DDL script. If that's the problem, I would rethink the approach.

    -Generate the DDL for all tables without constraint
    -Can generate the DDL for all primary key constraints
    -Can generate the DDL for all unique key constraints
    -Can generate the DDL for all foreign key constraints

    This is not solidarity all the DOF for a given in the file object. But the SQL will be radically simpler writing - there will be no need to even look at the dependency graph.

    Justin

  • How to solve the problems highlighted in each journal in the issues of the CBS

    Hello

    Please could someone help me decipher the CBS logs for two of my Vista machines and tell me how to solve the problems highlighted in each journal.

    Vista 1 machine has Vista Ultimate x 64 SP2 installed and has been implemented in the following way:

    • Installed Vista Ultimate SP1 from DVD
    • Apply all updates important, recommended, and optional through Microsoft Update
    • Applied SP2 via Microsoft Update
    • Apply all important updates, optional and recommended through Microsoft Update after that

    Machine Vista 2 has Vista Ultimate x 86 SP2 installed and has been implemented in the following way:

    • Installed Vista Ultimate SP1 from DVD
    • Apply all updates important, recommended, and optional through Microsoft Update
    • All the different ways to install SP2 and had no success in which I used the followed by the fix corrupt system analysis tool Pack of language without problems were detected but had to reinstall OS in order to reactivate Windows new
    • Reinstalled Vista Ultimate SP1 DVD
    • Installed SP2 with download of the Microsoft not by Microsoft Update website and this time it worked
    • Apply all updates important, recommended, and optional through Microsoft Update

    I searched on Google for months on how to solve the problems highlighted in the CBS logs but got too hypnotized and decided to consult you on how to solve the problems. I forgot to mention also that 11 updates of Windows would not apply via Microsoft Update on both machines and apply them manually in which they worked.

    Finally please can you give me a link to download CBS logs.

    Your help would be much appreciated.

    Thank you very much

    RocknRollTim

    https://social.technet.Microsoft.com/forums/Windows/en-us/54bff6db-0797-4655-A331-a86510c1b291/Vista-CBS-log-issues?Forum=itprovistasp and OneDrive (SkyDrive) for download to use collected files and after shot/screenshot. (Updated: 16/01/2012)

  • How to take the last 7 digits of a varchar column

    How to take the last 7 digits of a varchar2 colum

    COL1

    12345678

    12345

    1234567890123

    1234567

    Out put should be as below

    COL1

    2345678

    12345

    7890123

    1234567

    everything built in function or in any other way please

    Hello

    assuming that the entry contains only numbers, as in the example, the addition of 7 spaces to the left and selecting the 7 last characters toured:

    with dataset as

    (select col1 from column_value

    table

    (dbmsoutput_linesarray

    ("12345678"

    '12345 '.

    '1234567890123'

    "1234567".

    )

    )

    )

    Select col1

    , substr (lpad (", 7,' ') | col1-7) col1_last7

    of the dataset

    /

    COL1 COL1_LAST7

    -------------------- --------------------

    12345678 2345678

    12345 12345

    1234567890123 7890123

    1234567 1234567

    Rob

  • How to get the second Monday of each month in a given date range?

    In Oracle forms, how to get the second Monday of each month in a given date range?

    I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?

    WITH month_range AS

    (

    SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month

    , TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month

    OF the double

    )

    SELECT NEXT_DAY (6 + ADD_MONTHS (first_month

    , LEVEL - 1

    )

    , 'MONDAY '.

    ) AS second_monday

    OF month_range

    CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)

    ;

    Thanks in advance.

    Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.

    THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7

    END AS second_day

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • After you create an action to reduce the size and convert them to JPEG format, how to eliminate the word "copy" of each image name?

    After you create an action to reduce the size and convert them to JPEG format, how to eliminate the word "copy" of each image name?

    You can batch process using the image processor script and no user action should still be included in the process.  Check out our menu file > Scripts > image processor.

  • How to take the laboratory test, possible?

    I'm not able to study for vmware.

    I did the course, but the company has not set environment for me and work.

    How to take the laboratory test, possible?

    I need a help from you.

    Thank you

    ________________________________

    Thiago Rodrigues | Network management

    Associate. [email protected]

    Mobile: (011) 6122-0994

    www.DIGISYSTEM.com.br

    Engine certified Manager

    Certified Itil v2 Foundation

    ________________________________

    My VCP410 exam, it is not easy to take the exam without laboratory. Try to get a lab by installing a copy of assessment on VMware Play or work station. I hope this helps.

    Tim

    VCP on vSphere 4

  • How to reverse the counting of the af. : column-to-head-cell?

    Hi all

    I'm new to ADF and I hope someone out there can help me.

    In an application of ADF 11g with general of the Tables in the ADF skinning, I need for a particular table ADF to overturn the butchering of the header.
    It's a bad design, I know, but before I just reject the design because they can't do it, I'll try just so someone with more experience ADF knows how to do.

    In the .css file, I have the following:

    AF | : column-to-head-cell {background-color: #72b3dd;}
    do-family: Arial;
    make-weight: bold;
    do-size: 16px;
    color: #FFFFFF;
    padding-left: 15px;
    border-top: 2px solid #acd1eb;
    border-bottom: 2px solid #acd1eb;
    border-right: none;
    border-left: none;
    height: 47px;
    }

    If for example I try to add an inlineStyle for the af:column tag:

    < af:column sortable = "false".
    headerText = "first column heading.
    inlineStyle = "" background-color: Fuchsia; ">"

    -stripping for the cells of the row (e.g. af |: data in the table-row af |: column-cell data) may be overules, but not the header cell (af |: column-to-head-cell)

    Does anyone know how to reverse the counting for a column header cell in a Table of the ADF?

    Hello

    Why don't you use the inline style property and not the skin file? If you must run instance according to the count, then adds a styleClass name to the table. For example 'myHeaderChangeStyle' change the def of skin to

    AF | : column-to-head-cell {background-color: #72b3dd;}
    do-family: Arial;
    make-weight: bold;
    do-size: 16px;
    color: #FFFFFF;
    padding-left: 15px;
    border-top: 2px solid #acd1eb;
    border-bottom: 2px solid #acd1eb;
    border-right: none;
    border-left: none;
    height: 47px;
    }

    .myHeaderChangeStyle af | : column-to-head-cell {}
    background-color: Fuchsia;
    }

    Frank

  • kindly tell how to use the unique value of a table with the index 0

    kindly tell how to use the unique value of a table with the index 0

    Hi
     
    Yep, use Index Array as Gerd says. Also, using the context help ( + h) and looking through the array palette will help you get an understanding of what each VI does.
     
    This is fundamental LabVIEW stuff, perhaps you'd be better spending some time going through the basics.
     
    -CC
  • The line of the last line of each table page is going to be missing.

    Hi Experts,
    In OBIEE 11.1.1.6.0, I have a report contains more than one line. "When I click on" PDF "Print", the last line of each table page line will be missing. " Why?
    Are you facing the same case? How soluve this question? Thank you.

    Hey Kobe,

    The question, looks lke a bug. Here's the work around, change the table view, click the properties of content next to the text "Table" (at the top of the columns and measures) in the layout-> position In Border pane to choose custom and select only the bottom edge (horizontal line). Now export to pdf format, you must see the border for the last row on each page.

    Kind regards
    DpKa

  • How to take a field value in a table?

    How to take a field value in a table? its urgent...

    I recommend you read up a bit on JS. These are standard questions that are not

    associated with Acrobat, as such.

    I recommend this site: http://www.w3schools.com/js/default.asp

    Specifically, to answer your question, you can use the join() method.

    See here: http://www.w3schools.com/jsref/jsref_join.asp

    You can then convert this string to a number using the number I

    described previously.

  • How to add the new column in existing table to our desired location?

    How to add the new column in existing table to our desired location?

    For example, I have to add the new column 'course' before the salary column in the emp table.

    I think the best way is to add the column at the end of the table and create a new view with the order of the columns...

    Another option...

    places the data into a temporary table and recreate the table with the correct order of the columns, and then insert data to the table from the temporary table

    Refer

    Add column (from table) in the desired position

    Example:

    CREATE TABLE temp_my_user LIKE)

    SELECT * FROM password);

    DROP TABLE password;

    (Password) CREATE TABLE

    userID NUMBER

    , first name VARCAHR2 (25)

    , middleInitial VARCHAR2 (1)

    (, name VARCHAR2 (25));

    INSERT INTO password (userID, firstName, lastName)

    (SELECT username

    first name

    lastName

    OF temp_my_user);

    DROP TABLE temp_user;

  • How to assign the temporary tablespace to a table

    How to assign the temporary tablespace to a table

    temporary tablespace can be attributed to the user.

  • How to recover the second line of a table

    Hello

    Could someone let me know how to recover the second line of a table without using the coumn the names of columns in the table.

    By default the table EMP or used in the case of scott connection can be used as an example of table.


    Concerning
    select e.* from(
    select e.*,  rownum rn from emp e)e
    where e.rn =2
    

    did you expect that?

  • I want to take the source code of each Web page as input and address on it, how can I do this?

    I'll develop an add-on for mozilla firefox, but for this I need the source code for each page. This is necessary to find the tag button inside the source code, to search for the tag href in the source code, etc... So please help me for this.

    The forum of the add-on is here:
    https://forums.addons.Mozilla.org/

Maybe you are looking for