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

后端 未结 5 1306
心在旅途
心在旅途 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:08

    CURRENT_SCHEMA is the schema that will be assumed if you name an object without specifying its owner. For instance, if my CURRENT_SCHEMA is SCOTT, then SELECT * FROM EMP is the same as SELECT * FROM SCOTT.EMP. By default, when I first connect to Oracle, the CURRENT_SCHEMA is the same as CURRENT_USER.

    However, if I am connected as SCOTT, I can issue ALTER SESSION SET CURRENT_SCHEMA=JOE and then when I do SELECT * FROM EMP, it is interpreted as JOE.EMP rather than SCOTT.EMP. Of course, if I don't have the SELECT privilege on JOE.EMP, or JOE doesn't have an object named EMP, the SELECT will fail.

提交回复
热议问题