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

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

    There is also a performance difference between USER and using sys_context

    declare 
      v_result varchar2(100);
    begin
      for i in 1..1000000 loop
      v_result := sys_context('userenv','session_user');
      end loop;
    end;
    /
    
    -- 2.5s
    
    declare 
      v_result varchar2(100);
    begin
      for i in 1..1000000 loop
      v_result := user;
      end loop;
    end;
    / 
    
    -- 47s
    

    Also see https://svenweller.wordpress.com/2016/02/24/sequence-and-audit-columns-with-apex-5-and-12c/ and http://www.grassroots-oracle.com/2019/01/oracle-user-vs-sys-context.html

提交回复
热议问题