sys_context(''userenv'',''sessionid'') : SYS_CONTEXT « SQL PLUS Session Environment « Oracle PL/SQL Tutorial






SQL>
SQL>
SQL> create or replace function myFunction
  2  return varchar2
  3  authid current_user
  4  as
  5    myModule varchar2(48);
  6    cmd varchar2(500);
  7  begin
  8     cmd := 'select b.module ' ||'from v$session b ' ||'where b.audsid = sys_context(''userenv'',''sessionid'')';
  9     execute immediate cmd into myModule;
 10     return myModule;
 11  end;
 12  /

Function created.

SQL> select myFunction from dual;

1 row selected.


SQL> drop function myFunction;

Function dropped.

SQL>








29.64.SYS_CONTEXT
29.64.1.Use SYS_CONTEXT to retrieve the database name
29.64.2.Get current program with sys_context('userenv','sessionid') and v$session
29.64.3.sys_context(''userenv'',''sessionid'')