Vamsi Jayavarapu
Vamsi Jayavarapu

Reputation: 411

How to know currently logged in username in Oracle SQL?

How to know currently logged in username in Oracle SQL, if we are dealing with multiple users within the same DB, it is little bit confusing to understand!

Upvotes: 6

Views: 29829

Answers (2)

kibromhft
kibromhft

Reputation: 1057

There are many different ways.


Option 1
Use the V$SESSION view.

SELECT USERNAME FROM V$SESSION;

Option 2
This one gives all the detailed information because there are times that you have to locate locked sessions.

select
       substr(a.spid,1,9) pid,
       substr(b.sid,1,5) sid,
       substr(b.serial#,1,5) ser#,
       substr(b.machine,1,6) box,
       substr(b.username,1,10) username,
--     b.server,
       substr(b.osuser,1,8) os_user,
       substr(b.program,1,30) program
from v$session b, v$process a
where
b.paddr = a.addr
and type='USER'
order by os_user,username;

Upvotes: 0

Vamsi Jayavarapu
Vamsi Jayavarapu

Reputation: 411

By using this query we can get currently logged in user

select user from dual;

Upvotes: 18

Related Questions