Show users accessing database with same username from multiple locations and their count

Posted on 2011-04-28
Last Modified: 2013-12-18
SQL> select count(distinct(terminal)),username
  2  from dba_audit_session
  3  having count(distinct(terminal))>1
  4  group by username;

COUNT(DISTINCT(TERMINAL))          USERNAME                                              
-------------------------                           --------------                                        
                        2                                    AADM      

Need to find out from where (userhost,teminal,,,etc) its coming?
Question by:Cha1tu
    LVL 40

    Expert Comment

    Well you have the basic query done. What part is not working? DBA_AUDIT_SESSION (TERMINAL and USERHOST) has most of that info. So what is the question?
    LVL 7

    Expert Comment


    If you are looking for multiple locations, you must use 'userhost' instead of 'terminal'... Since you can use multiple terminals on the same host (= same location).

    If you want to know how to track down a host on a network, you should ask the question in the right zone... (there's commands like treaceroute, nslookup, etc. that allow tracing a network)

    LVL 2

    Author Comment

    @mrjoltcola: here its giving only username and COUNT(DISTINCT(TERMINAL))  right

    I want to display some other cloums like USERHOST,TERMINAL,OS_USERNAME....

    i want to know from which place(userhost) that user is connecting and wat is the terminal name
    LVL 40

    Expert Comment

    You are asking how to show count of distinct terminals, along with a row for each terminal (or host). That is combining a group / aggregate with a detail list. Sort of an odd query requirement. Just remove the count(distinct()) and add userhost and other needed columns, that are right there in dba_audit_session
    LVL 2

    Author Comment

    Can you give the query?
    LVL 40

    Accepted Solution

    Just be aware that the TERMCOUNT is the overall count of terminals.

    select distinct a.username, userhost, terminal, termcount from dba_audit_session a
      (select count(distinct(terminal)) termcount, username
       from dba_audit_session
       having count(distinct(terminal))>1
       group by username) b
     on a.username = b.username

    Open in new window


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
    Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
    This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
    This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now