Summary: in this tutorial, you will learn how to list users in the Oracle Database by querying from various system views.
TL;DR
List all users that are visible to the current user:
SELECT * FROM all_users;
Code language: SQL (Structured Query Language) (sql)
List all users in the Oracle Database:
SELECT * FROM dba_users;
Code language: SQL (Structured Query Language) (sql)
Show the information of the current user:
SELECT * FROM user_users;
Code language: SQL (Structured Query Language) (sql)
Oracle ALL_USERS
The ALL_USERS
view lists all users that are visible to the current user. However, this view doesn’t describe the users.
The following statement returns all users in the Oracle Database, sorted by created date from the latest to the earliest:
SELECT * FROM all_users
ORDER BY created;
Code language: SQL (Structured Query Language) (sql)
Here is the output:
This table illustrates the meanings of each column in the ALL_USERS
view:
Column | Datatype | NULL | Description |
---|---|---|---|
USERNAME | VARCHAR2(128) | NOT NULL | The name of the user |
USER_ID | NUMBER | NOT NULL | The ID of the user |
CREATED | DATE | NOT NULL | The date on which the user was created |
COMMON | VARCHAR2(3) | Specifies if a user is common ( YES ) or Local ( NO ) | |
ORACLE_MAINTAINED | VARCHAR2(1) | Indicates whether the user was created and maintained by Oracle-supplied scripts ( Y ). Note that you should not change these users directly except by modifying them by executing an Oracle-supplied script. | |
INHERITED | VARCHAR2(3) | Denotes where a user definition was inherited from another container (YES ) or not (NO ). | |
DEFAULT_COLLATION | VARCHAR2(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_SHARD | VARCHAR2(3) | In a sharded database, this column has either one of two possible values: YES and NO :
In a non-sharded database, the value is always |
Oracle DBA_USERS
The DBA_USERS
view describes all users in the Oracle database.
The following statement returns all users in the Oracle Database, sorted by created date from the latest to the earliest:
SELECT * FROM DBA_USERS
ORDER BY created DESC;
Code language: SQL (Structured Query Language) (sql)
This picture shows the partial output:
This table explains the meaning of each column in the DBA_USERS
view:
Column | Datatype | NULL | Description |
---|---|---|---|
USERNAME | VARCHAR2(128) | NOT NULL | The name of the user |
USER_ID | NUMBER | NOT NULL | The ID of the user |
ACCOUNT_STATUS | VARCHAR2(32) | NOT NULL | Account status of the user. Here is the valid list:
|
LOCK_DATE | DATE | The date on which the account was locked if the account status is LOCKED | |
EXPIRY_DATE | DATE | Expired date of the user | |
DEFAULT_TABLESPACE | VARCHAR2(30) | NOT NULL | The default tablespace of the user. |
TEMPORARY_TABLESPACE | VARCHAR2(30) | NOT NULL | The default tablespace for temporary tables |
LOCAL_TEMP_TABLESPACE | VARCHAR2(30) | The default local temporary tablespace for the user | |
CREATED | DATE | NOT NULL | The date on which the user was created |
INITIAL_RSRC_CONSUMER_GROUP | VARCHAR2(128) | The initial resource consumer group for the user | |
EXTERNAL_NAME | VARCHAR2(4000) | The external name of the user | |
PROXY_ONLY_CONNECT | VARCHAR2(1) | Specify if a user can connect directly (N ) or can only be proxied (Y ) by users who have proxy privileges for this account. | |
COMMON | VARCHAR2(3) | Specifies if a user is common ( YES ) or Local ( NO ) | |
ORACLE_MAINTAINED | VARCHAR2(1) | Indicate whether the user was created and maintained by Oracle-supplied scripts ( Y ). Note that you should not change these users directly except by modifying them by executing an Oracle-supplied script. | |
INHERITED | VARCHAR2(3) | Denotes where a user definition was inherited from another container (YES ) or not (NO ). | |
DEFAULT_COLLATION | VARCHAR2(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_SHARD | VARCHAR2(3) | In a sharded database, this column has either one of two possible values: YES and NO :
In a non-sharded database, the value is always |
Oracle USER_USERS
The USER_USERS
view describes the current user:
SELECT * FROM user_users;
Code language: SQL (Structured Query Language) (sql)
Here is the result set:
In this tutorial, you have learned how to list users in the Oracle Database using the ALL_USERS
, DBA_USERS
, and USER_USERS
views.