Skip to Main Content
  • Questions
  • Difference Between User and username in v$session

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Annapurna .

Asked: November 13, 2004 - 5:09 pm UTC

Last updated: November 15, 2004 - 1:27 pm UTC

Version: 9.2.0.4

Viewed 1000+ times

You Asked

What is the difference between user and username in v$session.
I thought there may not be any difference but i was finding both of them to different oracle username manier times. and user is being shown as SYS for most of the inactive sessions with different usernames

Regards

and Tom said...

user is a psuedo column -- so

select user from dual;

that works -- user is like a function, it returns the name of the currently logged in user.

username is an actual column in a table -- it is the username associated with that session.

so, when you see:

select user, username from table;

think:

select USER(), username from table;

user is a function, it is who you are.... if you describe v$session, you'll see that user is not a column in that view, it is a function really...

Rating

  (2 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Can they be different

Raju, November 15, 2004 - 4:36 am UTC

Am I right to assume that in all the cases the USER() and username values will be the same. Can they be different at all? If yes, please can you show with an example.

Thaks

Tom Kyte
November 15, 2004 - 6:43 am UTC

umm, USER is a function that returns YOUR NAME.

username is a database column.

there is no relationship whatsoever between the two. just

select user, username from v$session

on a database with multiple users logged in.

sorting...

Connor, November 15, 2004 - 9:16 am UTC

I wish they'd thought of that when they put a column called "USER" in v$sort_usage :-)

Tom Kyte
November 15, 2004 - 1:27 pm UTC

AGREED :)