How to List Users in the Oracle Database

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:

Oracle List Users - all_users

This table illustrates the meanings of each column in the ALL_USERS view:

ColumnDatatypeNULLDescription
USERNAMEVARCHAR2(128)NOT NULLThe 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 by 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.
IMPLICITVARCHAR2(3)Denotes if a user is a common user created by an implicit application (YES) or not (NO)
ALL_SHARDVARCHAR2(3)In a sharded database, this column has either one of two possible values: YES and NO:

  • YES: The user was created with shard DDL enabled. The user exists on all shards and the shard catalog.
  • NO: The user was created without shard DDL enabled. The user exists only in the database in which the user was created.

In a non-sharded database, the value is always NO in this column.

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:

Oracle List Users - dba_users

This table explains the meaning of each column in the DBA_USERS view:

ColumnDatatypeNULLDescription
USERNAMEVARCHAR2(128)NOT NULLThe name of the user
USER_IDNUMBERNOT NULLThe ID of the user
ACCOUNT_STATUSVARCHAR2(32)NOT NULLAccount status of the user. Here is the valid list:

  • OPEN
  • EXPIRED
  • EXPIRED(GRACE)
  • LOCKED(TIMED)
  • LOCKED
  • EXPIRED & LOCKED(TIMED)
  • EXPIRED(GRACE) & LOCKED(TIMED)
  • EXPIRED & LOCKED
  • EXPIRED(GRACE) & LOCKED
LOCK_DATEDATEThe date on which the account was locked if the account status is LOCKED
EXPIRY_DATEDATEExpired date of the user
DEFAULT_TABLESPACEVARCHAR2(30)NOT NULLThe default tablespace of the user.
TEMPORARY_TABLESPACEVARCHAR2(30)NOT NULLThe default tablespace for temporary tables
LOCAL_TEMP_TABLESPACEVARCHAR2(30)The default local temporary tablespace for the user
CREATEDDATENOT NULLThe date on which the user was created
INITIAL_RSRC_CONSUMER_GROUPVARCHAR2(128)The initial resource consumer group for the user
EXTERNAL_NAMEVARCHAR2(4000)The external name of the user
PROXY_ONLY_CONNECTVARCHAR2(1)Specify if a user can connect directly (N) or can only be proxied (Y) by users who have proxy privileges for this account.
COMMONVARCHAR2(3)Specifies if a user is common ( YES) or Local ( NO)
ORACLE_MAINTAINEDVARCHAR2(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.
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.
IMPLICITVARCHAR2(3)Denotes if a user is a common user created by an implicit application (YES) or not (NO)
ALL_SHARDVARCHAR2(3)In a sharded database, this column has either one of two possible values: YES and NO:

  • YES: The user was created with shard DDL enabled. The user exists on all shards and the shard catalog.
  • NO: The user was created without shard DDL enabled. The user exists only in the database in which the user was created.

In a non-sharded database, the value is always NO in this column.

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:

Oracle List Users - user_users

In this tutorial, you have learned how to list users in the Oracle Database using the ALL_USERS, DBA_USERS, and USER_USERS views.

Was this tutorial helpful?