Oracle List Users

Oracle List Users | In this post we will see how to list all users in the Oracle database? What is the query used to show all users in the Oracle database

In the Oracle database all information including user, userid, username, and e.t.c. are stored in some tables. If we know the name of the table where user information is stored then we can easily display all the users of the Oracle database.

Oracle List All Users

In the Oracle database, all user information is stored in ALL_USERS and DBA_USERS. The ALL_USERS view displays all users that are visible to the current user. The ALL_USERS view doesn’t describe the user.

SELECT * FROM all_users;

Example:-

SELECT username, user_id, created
FROM all_users;

It displays,

USERNAME         USER_ID    CREATED
---------------- ---------- ---------
XS$NULL          2147483638 29-MAY-14
KNOW                     49 05-SEP-21
KP                       48 20-JUL-21
APEX_040000              47 29-MAY-14
APEX_PUBLIC_USE          45 29-MAY-14
FLOWS_FILES              44 29-MAY-14
HR                       43 29-MAY-14
MDSYS                    42 29-MAY-14
ANONYMOUS                35 29-MAY-14
XDB                      34 29-MAY-14
CTXSYS                   32 29-MAY-14
APPQOSSYS                30 29-MAY-14
DBSNMP                   29 29-MAY-14
ORACLE_OCM               21 29-MAY-14
DIP                      14 29-MAY-14
OUTLN                     9 29-MAY-14
SYSTEM                    5 29-MAY-14
SYS                       0 29-MAY-14

18 rows selected.

We can also use DBA_USERS to list all users in the Oracle database. But the DBA_USERS view is accessible only to the database administrator. Therefore to execute the query below, you must log in as a database administrator.

SELECT * FROM dba_users;

Unlike ALL_USERS view, DBA_USERS contains detailed reports like:- username, user_id, password, account_status, lock_date expiry_da, default_tablespace, temporary_tablespace, created, profile, initial_rsrc_consumer_group.

Oracle List Users Using ALL_USERS

The ALL_USERS view contains the following columns:- user_id, username, and created (date of user creation), common, oracle_maintained, inherited, default_collation, implicit, and all_shard. We can display all users based on their creation date. The view is visible to all users, and it gives only a little information about the user, it doesn’t describe the user.

SELECT * FROM all_users
ORDER BY created DESC;

Table to show the meaning of all columns of ALL_USERS view,

ColumnDatatypeNULLDescription
USERNAMEVARCHAR2(30)NOT NULL Name of the user.
USER_IDNUMBERNOT NULLThe ID of the user.
CREATEDDATENOT NULLThe date on which the user was created.
COMMONVARCHAR2(3)Specifies if a user is common ( YES) or Local ( NO)
ORACLE_MAINTAINEDVARCHAR2(1)Indicates whether the user was created and maintained by Oracle-supplied scripts ( Y). Note that you should not change these users directly except modifying them by executing an Oracle-supplied script.
INHERITEDVARCHAR2(3)Denotes where a user definition was inherited from another container (YES) or not (NO).
DEFAULT_COLLATIONVARCHAR2(100)Specifies the default collation for the schema of the user.
IMPLICIT VARCHAR2(3)Denotes if a user is a common user created by an implicit application (YES) or not (NO)
ALL_SHARDVARCHAR2(3)In a shared database, this column has either one of two possible values: YES and NO.

Oracle List Users Using DBA_USERS

The DBA_USERS view is accessible to the database administrator, and it contains all the details about the user. It contains username, user_id, password, account_status, lock_date, expiry_da, default_tablespace, temporary_tablespace, created, profile, and initial_rsrc_consumer_group column.

SELECT * FROM dba_users
ORDER BY created DESC;

Table to show the meaning of all columns of DBA_USERS view,

ColumnDatatypeNULLDescription
USERNAMEVARCHAR2(30)NOT NULLName of the user.
USER_IDNUMBERNOT NULLThe ID of the user.
PASSWORDVARCHAR2(30)The password of the user.
ACCOUNT_STATUSVARCHAR2(32)NOT NULLAccount status of the user. 
LOCK_DATEDATEThe date on which the account was locked.
EXPIRY_DATEDATEThe expiry date of the user.
DEFAULT_TABLESPACEVARCHAR2(30)NOT NULLThe default tablespace of the user.
TEMPORARY_TABLESPACEVARCHAR2(30)NOT NULLThe default tablespace for temporary tables.
CREATEDDATENOT NULLThe date on which the user was created.
PROFILEVARCHAR2(30)NOT NULLThe profile of the user.
INITIAL_RSRC_CONSUMER_GROUPVARCHAR2(30)The initial resource consumer group for the user.
EXTERNAL_NAME VARCHAR2(4000)The external name of the user.

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Leave a Comment

Your email address will not be published. Required fields are marked *