What is the difference between USER() and SYS_CONTEXT('USERENV','CURRENT_USER')?

后端 未结 5 1315
心在旅途
心在旅途 2021-01-01 16:31

In an Oracle Database, what are the differences between the following:

  • user()
  • sys_context(\'USERENV\', \'CURRENT_USER\')
  • sys_context(\'USEREN
5条回答
  •  星月不相逢
    2021-01-01 17:07

    From the manual at: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions184.htm#SQLRF51825

    CURRENT_USER

    The name of the database user whose privileges are currently active. This may change during the duration of a session to reflect the owner of any active definer's rights object. When no definer's rights object is active, CURRENT_USER returns the same value as SESSION_USER. When used directly in the body of a view definition, this returns the user that is executing the cursor that is using the view; it does not respect views used in the cursor as being definer's rights.

    SESSION_USER

    The name of the database user at logon. For enterprise users, returns the schema. For other users, returns the database user name. This value remains the same throughout the duration of the session.

    So there is a difference between SESSION_USER and CURRENT_USER especially when CURRENT_USER is used in a stored procedure or function.

    I have to admit that I don't know what the term "enterprise user" means though.

    Btw: there is a third one:

    SESSION_USERID

    The identifier of the database user at logon.

提交回复
热议问题