Oracle Show Current User

Oracle Show Current User | In the previous tutorial, we see how to list all users of the Oracle database? How we can use ALL_USERS and DBA_USERS views to list all users. Now, in this tutorial, we will see how to show the current users in the Oracle database?

Show current user name in Oracle using dual,

SELECT user FROM dual;

Output:-

USER
------------------------------
KNOWP

Using sys_context to show the current user in the Oracle database,

SELECT sys_context('USERENV','CURRENT_USER') FROM dual;

Output:-

SYS_CONTEXT('USERENV','CURRENT_USER')
-------------------------------------
KNOWP

The above two queries show the only username and don’t give much detail on the current user. To show the current users in the Oracle database we can use the USER_USERS view. This table contains the currently logged user details.

SELECT * FROM user_users; 

This view contains the following details:- username, user_id, account_status, lock_date, expiry_date, default_tablespace, temporary_tablespace, local_temp_tablespace, created, initial_rsrc_consumer_group, external_name, proxy_only_connect, common, oracle_maintained, inherited, default_collation, implicit, all_shard, password_change_date.

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.
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.
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 *