SQL query to find top 5 users having more rows/data in table

Dear experts,
OS = HP-UX
Database = Oracle 9.2.0.8
AC users = 600
Ex:-
select * from all_users where username like 'AC%';
AC_1
AC_2
AC_3
AC_4
AC_5
AC_6
AC_.
AC_.
AC_.
AC_600
Each AC user having same tables INCOMING, OUTGOING
Now i need to find top 5 users having more rows/data in INCOMING , OUTGOING tables. I tried this:
SQL>conn AC_1/pwd
select 'select count(*) from '||table_name||';' from user_tables;
But i get max counts info only for this AC_1 user , however, i need top 5 users having more rows/max counts query.
Thank you,

source : oracle forums
May be , this one.. not tested though.
Before doing this you need to have select_catalog_role
WITH tmp
     AS (SELECT owner,
                table_name,
                TO_NUMBER (
                   EXTRACTVALUE (
                      xmltype (
                         DBMS_XMLGEN.getxml (
                            'select /*+ PARALLEL*/ count(*) c from '
                            || table_name)),
                      '/ROWSET/ROW/C'))
                   Cnt
           FROM dba_tables
          WHERE 1 = 1 AND table_name IN ('INCOMING', 'OUTGOING')),
     tmp1
     AS (SELECT a.*,
                MAX (cnt)
                   OVER (PARTITION BY a.table_name ORDER BY a.cnt DESC)
                   maxcnt
           FROM tmp a)
SELECT DISTINCT a.*
  FROM tmp a, tmp1 b
WHERE a.cnt = b.maxcnt AND a.table_name = b.table_name;

Similar Messages

  • SQL Query to Find out User has what all resources provisioned !

    Hi Guys ,
    Does any one have a SQL query to find out what resources are provisioned to a particular user ?
    Thanks
    Suren

    Hi,
    Hope this will help you.
    SELECT distinct usr_login as "IdM User ID",
    usr_employeeID as "Employee ID",
    usr.USR_FIRST_NAME as "First Name",
    usr.USR_LAST_NAME as "Last Name",
    usr_status
    as "User Status",
    USR_EMP_TYPE as "Employee Type",
    obj.obj_name as "Application Resource",
    ost_status as "Application Resource Status",
    FROM ost,oiu,obj,usr,obi
    WHERE oiu.ost_key = ost.ost_key AND obj.obj_key = obi.obj_key AND oiu.usr_key = usr.usr_key
    AND ost_status in ('Provisioned','Revoked','Disabled', 'Provisioning')
    AND oiu.obi_key=obi.obi_key
    AND usr_EmployeeID like '11111'
    This query will provide all the resources to which the user is linked with and the resource status is in 'Provisioned','Revoked','Disabled', 'Provisioning' status for a particular employeed ID, I am not completely sure whether I have given the Employee ID column from USR table as correct or not. Verify once and query the DB

  • SQL Query to find menus and submenus attached to responsibility

    Hi,
    I am looking for help to find out a sql query to pull out the list of all the menu's associated with each of the responsibilities assigned to users. Please let me know any SQL query to find out menus attached for responsibilities assigned to users.

    835129 wrote:
    I was asked by my lead to list out responsibilities and attached menus and I was asked to submit the output from production. In the metalink note provided by you it was asked to create table collecting all menu id's and I cannot create any tables in production. Apart from this there were 1000's of users with different responsibilities and different menus. I cannot collect all of the users menu ids.
    I just want to list out responsibilities and attached menus. Is that something you can helpout withhttps://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_vl+AND+fnd_menu&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    https://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_tl+AND+FND_MENU_ENTRIES_TL&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Please search the forum for these tables/views and you should get many hits:
    FND_MENU_ENTRIES_TL
    FND_MENU_ENTRIES_VL
    FND_RESPONSIBILITY_TL
    FND_RESPONSIBILITY_VL
    Thanks,
    Hussein

  • Query to find the application user

    Hi,
    what is the query to find the application user in sql command?
    I tried the below query
    select app_user from dual;
    app_user invalid identifierthanks.

    Use bind variable notation:
    select :app_user from dualThis is a reduced example, right? Can't see any reason to run such a query instead of using one of the documented methods of referencing built-in substitution values.
    Please try to use the documentation to answer such basic questions.

  • Sql query to find the balances for a customer account wise.

    Hi,
    Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
    presently we are using this query, but the output doesnot return the expected result.
    SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
    FROM      ra_cust_trx_line_gl_dist_all gld,
              gl_code_combinations c,
              ar_payment_schedules_all ps,
              RA_CUSTOMER_TRX_ALL rat,
              ra_customers rc
    WHERE      c.CHART_OF_ACCOUNTS_ID = 101
    and gld.code_combination_id = c.code_combination_id
         and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
         and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
    and ps.customer_id=rc.customer_id
         and ps.status='OP'
         and ps.gl_date <= :PDATE
         and ps.org_id=:PORGID
         and ps.class in ('GUAR','INV','DM','DEP')
    and c.SEGMENT4=:Account_id
    and ps.customer_id=:Customer_id
    Thanks in advance.
    Kalyan.

    Can someone help us with this.

  • Can anybody provide the SQL query to find the files uploaded in a particular folder?

    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

    Nevin,
    Be great if we could know the version of Portal. For Rel. 1, here's the query
    select id,masterthingid from wwv_things
    where siteid = &site
    and cornerid = &corner
    &site - Content Area id
    &corner - Folder id
    if you don't know the folder id, use
    select id from wwv_corners where siteid = &site
    and name = &folder
    Hope this helps. I have run into this situation before. Usually, the culprits were
    one of the following:
    1. Junk Characters in description of item (caused due to Copy-Paste)
    2. Special Characters in the File name
    Hi All,
    Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
    GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
    Any help is greatly appreciated.
    With best regards,
    Nevin

  • Sql query to find all contacts for an account

    I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
    I am also looking for sql query to find all ship to addresses for an account number.
    Thanks.

    Can you also post the query for people who read this post and are also looking for an answer?
    Regards,
    Johan Louwers.

  • SQl query to find incompatibility defined

    If two programs are defined as incompatible with one another, the data these programs cannot access simultaneously must also be identified.
    This can be found from concurrent program->define from front end ebs login, but is there any SQL query to find this for a particular program or request set??
    Thanks in advance.

    Please search the forum before posting similar questions.
    Concurrent-Conflict
    Re: Concurrent-Conflict
    Thanks,
    Hussein

  • SQL Query to find DN and phone Load

    Hi All,
    We are using Call Manager 8.6 [one PUB and 4 SUBs] and have different IP phone models .
    IP phone model have different LOAD working with them like few 3905 have cmterm-3905.9-2-2-0 while some have cmterm-3905.9-2-2ES7 .
    Is there any way/SQL Query  to find out what all phone model with DN are running 3905.9-2-2.0 LOAD?
    regds,
    aman

    Hey Aman,
    Hope all is well my friend!
    Just to add a note to my friend Carlo's good info here (+5!)
    Try;
    Device> Device Settings> Firmware Load Information>Device Not Using Default Load
    This will show you any phones that deviate from the "device defaults" Fimware And if you click
    on any device listed here it will show the actual Firmware that is being used on the specified device.
    Cheers!
    Rob

  • SQL query to find sqlnet.ora parameters

    Hi All,
    I am working 11g RAC /solaris 9
    I want have sql query to find values of sqlnet.ora parameters
    May be values of SQLNET.INBOUND_CONNECT_TIMEOUT
    SQLNET.SEND_TIMEOUT, SQLNET.RECV_TIMEOUT
    Thanks
    raj

    The sqlnet.ora file is the profile configuration file. It resides on the client machines and the database server.
    Profiles are stored and implemented using this file. The database server can be configured with access control parameters in the sqlnet.ora file.
    These parameters specify whether clients are allowed or denied access based on the protocol.
    The sqlnet.ora file enables you to do the following:
    Specify the client domain to append to unqualified names
    Prioritize naming methods
    Enable logging and tracing features
    Route connections through specific processes
    Configure parameters for external naming
    Configure Oracle Advanced Security
    Use protocol-specific parameters to restrict access to the database
    By default, the sqlnet.ora file is located in the ORACLE_HOME/network/admin directory. The sqlnet.ora file can also be stored in the directory specified by the TNS_ADMIN environment variable.
    You can not query on this file sqlnet.ora as tnsnames.ora file.
    Regards
    Mahir M. Quluzade

  • SQL query to find access database files?

    Odd request, but does anyone have a SQL query to find files? Specifically, I am looking for machines that have access databases on them. .mdb & .accdb

    Have you enabled inventory for them?
    Garth Jones | My blogs: Enhansoft and
    Old Blog site | Twitter:
    @GarthMJ
    i was trying to figure out where that option was but couldn't find it under hierarchy settings. perhaps it's been changed since 2012 R2? can you help point it out?

  • Writing a query to find out who is having a given responsibility name.

    Hi,
    I am new to Oracle Apps and have no idea about its tables. Can anyone please help me in writing a query to find out who is having a given responsibility name.
    Thanks in advance.
    Regards
    Himanshu

    Hi
    you can get required data by using this query
    select usr.user_name
    ,     res.responsibility_name
    from fnd_user usr
    ,     FND_USER_RESP_GROUPS_DIRECT usrrep
    ,     fnd_responsibility_tl res
    where usr.user_id=usrrep.user_id
    and usrrep.responsibility_id=res.RESPONSIBILITY_ID
    group by usr.user_name,res.responsibility_name
    Regards,
    Venky

  • Write the sql query to find largest value in row wise without using   great

    write the sql query to find largest value in row wise without using
    greatest fuction?

    Another not so good way, considering you want greatest of 4 fields from a single record:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (Select 100 col1,200 col2,300 col3,400 col4 from dual
      2  union select 500,600,700,800 from dual
      3  union select 900,1000,1100,1200 from dual
      4  union select 1300,1400,1500,1600 from dual
      5  union select 1700,1800,1900,2000 from dual
      6  union select 2100,2200,2300,2400 from dual
      7  union select 2800,2700,2600,2500 from dual
      8  union select 2900,3000,3100,3200 from dual)
      9  SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) Max_value
    10  FROM
    11  (SELECT (CASE WHEN col1_col2 > col2_col3 THEN col1_col2 ELSE col2_col3 END) col1,
    12         (CASE WHEN col2_col3 > col3_col4 THEN col2_col3 ELSE col3_col4 END) col2,
    13         (CASE WHEN col3_col4 > col4_col1 THEN col3_col4 ELSE col4_col1 END) col3
    14  FROM
    15  (SELECT (CASE WHEN col1 > col2 THEN col1 ELSE col2 END) col1_col2,
    16         (CASE WHEN col2 > col3 THEN col2 ELSE col3 END) col2_col3,
    17         (CASE WHEN col3 > col4 THEN col3 ELSE col4 END) col3_col4,
    18         (CASE WHEN col4 > col1 THEN col4 ELSE col1 END) col4_col1
    19* FROM t))
    SQL> /
    MAX_VALUE
           400
           800
          1200
          1600
          2000
          2400
          2800
          3200
    8 rows selected.
    SQL> Edited by: AP on Sep 21, 2010 6:29 AM

  • Sql query to find dependencies for a table

    Hi All,
    I am having a table (REPT_ALL) with dependent objects on it ( child tables, indexes, constraints, views, synonyms, sequences , packages,procedures,functions,triggers).
    I want the query to find out all the above dependencies for the above table(REP_ALL).
    I m looking for the query to find dependencies inorder to find out the risks before dropping the above table(drop table REP_ALL cascade constraints)?
    Thnx

    To find foreign key constraints for a table you cannot use DBA_DEPENDENCIES but you have to use DBA_CONSTRAINTS.
    Example Re: Find out foreign key column

  • In  a SQL query whihc has join, How to reduce Multiple instance of a table

    in a SQL query which has join, How to reduce Multiple instance of a table
    Here is an example: I am using Oracle 9i
    is there a way to reduce no.of Person instances from the following query? or can I optimize this query further?
    TABLES:
    mail_table
    mail_id, from_person_id, to_person_id, cc_person_id, subject, body
    person_table
    person_id, name, email
    QUERY:
    SELECT p_from.name from, p_to.name to, p_cc.name cc, subject
    FROM mail, person p_from, person p_to, person p_cc
    WHERE from_person_id = p_from.person_id
    AND to_person_id = p_to.person_id
    AND cc_person_id = p_cc.person_id
    Thnanks in advance,
    Babu.

    SQL> select * from mail;
            ID          F          T         CC
             1          1          2          3
    SQL> select * from person;
           PID NAME
             1 a
             2 b
             3 c
    --Query with only ne Instance of PERSON Table
    SQL> select m.id,max(decode(m.f,p.pid,p.name)) frm_name,
      2         max(decode(m.t,p.pid,p.name)) to_name,
      3         max(decode(m.cc,p.pid,p.name)) cc_name
      4  from mail m,person p
      5  where m.f = p.pid
      6  or m.t = p.pid
      7  or m.cc = p.pid
      8  group by m.id;
            ID FRM_NAME   TO_NAME    CC_NAME
             1 a          b          c
    --Expalin plan for "One instance" Query
    SQL> explain plan for
      2  select m.id,max(decode(m.f,p.pid,p.name)) frm_name,
      3         max(decode(m.t,p.pid,p.name)) to_name,
      4         max(decode(m.cc,p.pid,p.name)) cc_name
      5  from mail m,person p
      6  where m.f = p.pid
      7  or m.t = p.pid
      8  or m.cc = p.pid
      9  group by m.id;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 902563036
    | Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |        |     3 |   216 |     7  (15)| 00:00:01 |
    |   1 |  HASH GROUP BY      |        |     3 |   216 |     7  (15)| 00:00:01 |
    |   2 |   NESTED LOOPS      |        |     3 |   216 |     6   (0)| 00:00:01 |
    |   3 |    TABLE ACCESS FULL| MAIL   |     1 |    52 |     3   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       4 - filter("M"."F"="P"."PID" OR "M"."T"="P"."PID" OR
                  "M"."CC"="P"."PID")
    Note
       - dynamic sampling used for this statement
    --Explain plan for "Normal" query
    SQL> explain plan for
      2  select m.id,pf.name fname,pt.name tname,pcc.name ccname
      3  from mail m,person pf,person pt,person pcc
      4  where m.f = pf.pid
      5  and m.t = pt.pid
      6  and m.cc = pcc.pid;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4145845855
    | Id  | Operation            | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |        |     1 |   112 |    14  (15)| 00:00:01 |
    |*  1 |  HASH JOIN           |        |     1 |   112 |    14  (15)| 00:00:01 |
    |*  2 |   HASH JOIN          |        |     1 |    92 |    10  (10)| 00:00:01 |
    |*  3 |    HASH JOIN         |        |     1 |    72 |     7  (15)| 00:00:01 |
    |   4 |     TABLE ACCESS FULL| MAIL   |     1 |    52 |     3   (0)| 00:00:01 |
    |   5 |     TABLE ACCESS FULL| PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |   6 |    TABLE ACCESS FULL | PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    |   7 |   TABLE ACCESS FULL  | PERSON |     3 |    60 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - access("M"."CC"="PCC"."PID")
       2 - access("M"."T"="PT"."PID")
       3 - access("M"."F"="PF"."PID")
    PLAN_TABLE_OUTPUT
    Note
       - dynamic sampling used for this statement
    25 rows selected.
    Message was edited by:
            jeneesh
    No indexes created...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • Delivery Document GI date

    Beng a newbie I had a few questions on delivery document. When is/should a delivery document be created in the life of a sales order? Is this delivery GI date considered a committed date or still a planned? Will the GI date also show on schedule line

  • Is something wrong with the manga section in ibooks?

    It has me confused since I started getting manga volumes through ibooks. A few days I went to check available books in the manga section in comics and graphics novels. If I go through from the categories link in the side, It's blank now. If I go thro

  • Pages to iweb

    Hi, I am wondering if it is possible to export pages created files and put them on to my website using iweb whilst still maintaing the pages format? Thanks

  • Error installing enterprise edition

    Hi, I have a problem when I try to install oracle enterprise edition 10.2.0. The installation ends and when I try to connect to the em I get no respnse from my explorer. I opened the emca log file and in the last lines it has : SEVERE: Error starting

  • ORA-01476: divisor is equal to zero Error in tabular form

    Hello, My tabular form will give me this error sometimes: Error in add row internal routine: ORA-01476: divisor is equal to zero. I don't understand what causes it. On the form I have a on load - before header process that will add 5 blank rows autom