Count for each table

Hello

I try to count (*) for all the table owned by a user
I have the following error

What's wrong?
Thank you
declare
2 i the number;
3 t_owner varchar2 (20);
4 t_table_name varchar2 (20);
5. start
6 t in (select * from all_tables where owner = "MISAMM")
7 loop
8 t_owner: = t.owner;
9 t_table_name: = t.table_name;
10 dbms_output.put_line (' :'|| Table t_table_name);
11 dbms_output.put_line (' owner :'|| t_owner);
12 select count (*) in I of t_owner.t_table_name;
14 dbms_output.put_line ('Table :'|| t.table_name |) "lines :'|| TO_CHAR (i));
15 end loop;
16 end;
17.
Select count (*) in I of t_owner.t_table_name;
*
ERROR on line 12:
ORA-06550: line 12, column 37:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 12, column 1:
PL/SQL: SQL statement ignored


Elapsed time: 00:00:00.01

Hello

The names of the tables come display of metadata dynamically. Thus, you should use "immediate execution".

declare
  i            number;
  t_owner      varchar2(20);
  t_table_name varchar2(20);
begin
  for t in (select * from all_tables where owner = 'MISAMM')
  loop
    t_owner      := t.owner;
    t_table_name := t.table_name;
    dbms_output.put_line('Table:' || t_table_name);
    dbms_output.put_line('Owner:' || t_owner);
    execute immediate 'select count(*) from ' || t_table_name
      into i;
    dbms_output.put_line('Table:' || t.table_name || ' rows:' || to_char(i));
  end loop;
end;
/

Also, I wonder why you are not satisfied with the "num_rows" user_tables and all_tables column?

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

  • Are there records of the sys the timestamp of change for each table?

    I noticed that the sys "object" records just the creation and the timestamp of DDL operation.
    But I need the timestamp of change (for example, insert, update, delete, etc.) for my paintings. Otherwise, I fear that I must create the trigger for each table it's hard work.

    You can use scn_to_timestamp (max (ora_rowscn)) for the dml changes

  • How to extract .csv for each table

    Hi all

    I have a query:

    Select distinct ' SELECT * FROM BILL_M.' | Table_name | ';' from all_tab_columns t
    where t.owner = 'BILL_M. '
    and table_name like '% DICT '.

    The query returns 80 s table... How can I extract these 80 to 80 csvs table?

    Any help is appreciated.

    Kind regards.

    Just an example as a starting point...

    As user sys:

    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    /
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /
    

    As myuser:

    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      --
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    

    This allows the header line and the data to write into files separate if necessary.

    for example

    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    
    PL/SQL procedure successfully completed.
    

    Output.txt file contains:

    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10
    

    The procedure allows for the header and the data to separate files if necessary. Just by specifying the file name "header" will put the header and the data in a single file.

    Adapt to the exit of styles and different types of data are needed.

    You can then call this procedure for all the tables that you want to extract, with names appropriate for each.

  • Create a virtual channel that increases a counter for each iteration of a cyclic load test

    We will be a long period of cyclic fatigue tests, and I wish I could keep track of which iteration we are on this block.  The current plan is to test for 10 hours at 15 Hz, and then stop test for 2 hours for an inspection of the structure.  Later tests will begin upward.  Each of these blocks of 10 hours can start at a number of 0, but I would like to follow the release of our cell so that when he sees a rising edge (with filtering to take account of any noise) it will increase a 1 meter.  Each sample will then save this number in a column in the data file.  It doesn't have to be perfect in the measurement on the forehead, he sees the new cycle, but there need to be specific in the way that it is not miss or as an additional cycle.

    Is something like this in Signal Express full?

    Yes, what you are proposing is possible with SignalExpress full. You can call LabVIEW signal express code, so call a LabVIEW VI, which contains your counter code is a way to do it. If want to do entirely in SignalExpress you can use DAQmx features by browsing up to add a step > acquire signals > DAQmx acquire and put in place a task entry counter to match your needs.

  • Number of records per column in each table

    Hi all

    I need to get the number of records by column for each table in a schema.

    Is there a way I get the list of columns in each table in a schema and get the number of records per column where the count > 0?

    We have oracle 10g

    Thank you

    Smidreb wrote:
    You are right, but we're going to run the script as soon as we move

    the script below gives me a correct result.

    If it works well for you, then it works OK for me.

    Realize that Oracle is that I/O block-level.
    As a general rule, any LINE is a single block.
    Realize that is 1 column "count (*)" is correct, then all the columns in the same row are correct.
    This obsessive compulsion to count each COLUMN in each LINE borders on real PARANOIA!

  • the analysis of a word table of ms with different numbers of columns for each row

    I'm reading in a MS Word table that contains 20 lines, each with a different number of columns.  I have to iterate over each line then I iterate on each column of the row and read his text.  I don't know a way to find out how to stop an iteration on the columns.  Is a property or a method which tells you the number of columns in a specific line for a table in MS Word?

    ID says:

    I'm reading in a MS Word table that contains 20 lines, each with a different number of columns.  I have to iterate over each line then I iterate on each column of the row and read his text.  I don't know a way to find out how to stop an iteration on the columns.  Is a property or a method which tells you the number of columns in a specific line for a table in MS Word?

    For each row, use the count property of cells. Since there a number of subject lines is the number of columns.

    Ben64

  • I need a query that selects the amount of records for each day of a table.

    I need a query that selects the amount of records for each day of a table.
    For example, the result would be:

    1 14 date
    Date 2-3

    etc.

    Any ideas?

    Sort:

    SELECT count ([IDCommentaire]), convert (varchar, dateAdded, 112)

    OF COMMENTSgroup by convert (varchar, dateAdded, 112)

  • Count values not null for each column in a database

    Hello

    I need to write a routine that counts how many values a not null for each column in a database.
    The first idea would be to loop on all_tables / all_tab_cols and write a select statement as
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM '||table_name||' WHERE '||column_name||' IS NOT NULL' INTO v_count;
    However, this would mean a complete table for all columns not indexed scan. It's about when I have a maximum of 59 columns for a table with millions of rows.

    A better idea? I don't have the exact number. For example, for the number of rows in a table, I just use all_tables.num_rows.

    Concerning
    Marcus

    Ask the NUM_NULLS of the ALL_TAB_COLS column (and subtracting the total of the lines).

  • PLEADING... I NEED help with the boxes, one for each row in table.

    I have a tabular presentation I want to use to process once that will process once for each line that has had its check box selected. I worked on it... It seems... forever. I almost gave up. More than once I thought I had it all to find that I have no work.

    It seems always executed once for each row in the set of lines in the displayed table and I care about her contract so that the lines checked.

    Here is my select statement...
    Select
    APEX_ITEM. CHECKBOX (2, ISSUE_KEY, DECODE (issue_closed, 'Yes', 'CLOSED', 'No', 'DISABLED', null)) CHECK_KEY;
    TO_CHAR (ISSUE_DATE, ' ' DD-MON-YYYY HH24:MM:SS) FAILURE_DATE,.
    ISSUE_COMMENTS
    QUESTIONS


    I have a submit button that runs the following process
    DECLARE
    v_org_comments varchar2 (1024): = ";
    BEGIN
    BECAUSE me in 1... APEX_APPLICATION. G_F02. COUNTING LOOP
    SELECT ISSUE_COMMENTS
    IN v_org_comments
    QUESTIONS
    WHERE ISSUE_KEY = APEX_Application.g_f02 (i);

    UPDATE PROBLEMS
    SET
    ISSUE_COMMENTS = v_org_comments | » ' || : P4_X_ODF_NOTES,.
    ISSUE_CLOSED = "Yes"
    where ISSUE_KEY = APEX_Application.g_f02 (i);
    COMMIT;
    END LOOP;
    END;

    Hello

    I had the same problem. It seems that if you pass your columns to the columns in standard report it will fire for the checked columns. But if you proceed towards editable fields each line is treated as checked.
    So if you use line selector instead of manually creating check boxes and have a hidden primary key
    field, you can then use something like

    BECAUSE me IN 1.APEX_APPLICATION. G_F01. COUNTING LOOP
    UPDATE


    SET
    WHERE =
    APEX_APPLICATION. G_F02 (APEX_APPLICATION. G_F01 (i));
    END LOOP;

  • How to count the records for each region day and conditional

    Hello

    I need to create a report where I list activities for a month and the number of specific Type for each days activities. something like below

    Number of days in the month where Type = 'A' Count where Type = B
    January 1, 2009 2 3
    January 2, 2009 7 6
    January 3, 2009 8 7
    ----

    -----
    January 31, 2009 4 6

    I tried with the creation of conditional region for each row of table for every day, but it does not work. I use below for conditional region-

    <? xdofx:If substr (to_date ('20': substr (Planned, 9, 2) |)) » -'|| substr (Planned, 1, 2). » -'|| (substr (Planned, 4, 2), 'MM-DD-YYYY'), 4, 2) = 01? > <? Planned? > <? end if? >
    But it is not functional and do not know how to count records in the table for each date as well.

    Can anyone help in it as soon as possible. I'm quite new to BI.

    Thnks

    You can mark it as resolved... :D

    Kind regards
    Colectionaru

  • How to find the value max and min for each column in a table 2d?

    How to find the value max and min for each column in a table 2d?

    For example, in the table max/min for the first three columns would be 45/23, 14/10, 80/67.

    Thank you

    Chuck,

    With color on your bars, you should have enough experience to understand this.

    You're a loop in the table already.  Now you just need a function like table Max and min. loop.  And you may need to transpose the table 2D.

  • write 1 d digital table in a binary file and start a new line or insert a separator for each loop writing file

    Hello:

    I'm fighting with digital table of 1 d writeing in a binary file and start a new line or insert a separator for each loop writing file. So for each loop, it runs, LABVIEW code will collect a table 1 d with 253 pieces of a spectrometer. When I write these tables in the binay file and the following stack just after the previous table (I used MATLAB read binary file). However whenever if there is missing data point, the entire table is shifted. So I would save that table 1-d to N - D array and N is how many times the loop executes.

    I'm not very familiar with how write binary IO files works? Can anyone help figure this? I tried to use the file position, but this feature is only for writing string to Bodet. But I really want to write 1 d digital table in N - D array. How can I do that.

    Thanks in advance

    lawsberry_pi wrote:

    So, how can I not do the addition of a length at the beginning of each entry? Is it possible to do?

    On top of the binary file write is a Boolean entry called ' Prepend/chain on size table (T) '.  It is default to TRUE.  Set it to false.

    Also, be aware that Matlab like Little Endian in LabVIEW by default Big Endian.  If you probably set your "endianness" on writing binary file as well.

  • call a stored procedure for each row in the transitional attribute and display the data in the form of af: table. The other rows are based on the entities

    Hi Experts,

    JDeveloper 12.1.3.0.0

    I have a VO based on entity object. With a column of the VO is transient attribute (I created).

    I need to call a stored procedure for each row in the transitional attribute and display the data in the form of af: table. As well as other attributes.

    So can anyone suggest how can I achieve this?

    Thank you

    AR

    I think that you need a stored function (which returns the value) in this case, is not?

    Take a look at:

    https://docs.Oracle.com/CD/B31017_01/Web.1013/b25947/bcadvgen005.htm

    and search for:

    Invoking stored function with only Arguments in

    call your function in the Get attribute and return value accessor...

  • How to map the entered value of attribute column to another attribute in the table for each row.

    Hi Experts ADF,

    JDev 12 c.

    I create a button and a table below. If the user clicks on the button create, I invoke CreateInsert. The new line now appears as an editable fields.

    So I suppose I have a column that is displayed in editable mode. If the user enters values in that. Has another column B whose value is not displayed in the UI must have the same value as the column.

    This occurs for each row added. During the click on save if user entered 2 in column A, then the value in column B must be same 2.

    Thank you

    Roy

    There is more than one way, for example:

    Generate ViewRowImpl Java class (with generate audited accessors) you will get for an attribute setter.

    Change the Set accessor to set the attribute B (IE, calling setAttribute ("B", value)) after setting a value

    OR, write valueChangeListener for inputText representative and set the B attribute to the same value

Maybe you are looking for

  • synchronization of computer desk getting laptop notebook desktop no

    I've installed sync first on the laptop, then on the desk. All the Favorites on the desktop have been replaced by the few that I had on the laptop. I disconnected the office and retrieved all bookmarks. I would like to sync the phone and having all b

  • Libretto U100 - do not hibernate properly

    Hello My laptop do not hibernate properly. He used to work perfectly. I've changed anything so I don't know why this is happening. The symptoms are: 1 close the lid, XP traverse prepares him to Hibernate process, then is put into hibernation. After a

  • I have Vista recovery DVD on the English language?

    Hi, I bought a satellite A100-095 and I am very satisfied with the product. My problem is that I live in Italy and so I have windows vista Italian language. I'm a developer and vista comes with .net framework 2.0 pre-installed in Italian language, I

  • Focus Magnifier button sony a99

    Hello I have a question for shooting video on the A99 motorway. When I chose the M (manual setting of the photo) on the recording of the camera and press the shutterspeed automatically adjust when moving in a different light setting. My question is h

  • "c:\windows\system32\dbghelp.dll" "not designed to run on windows or it contains an error.

    Original title: c:\windows\system32\dbghelp.dll In the few weeks whenever I turn on my computer, try to save a document in Notepad or listen to music on windows media player, I get this error message "bad image" which appears again about 5 times in a