Thursday, March 1, 2018

Oracle: sys_context() getting all user environment variables


PROBLEM
Get list and values of ALL available user environment variables in an Oracle session. All in one shot. 

SOLUTION:

 select sys_context('userenv','ACTION'                   ) as FUNC,'ACTION' as PARAM  from dual union all
 select sys_context('userenv','AUDITED_CURSORID'         ),'AUDITED_CURSORID'         from dual union all
 select sys_context('userenv','AUTHENTICATED_IDENTITY'   ),'AUTHENTICATED_IDENTITY'   from dual union all
 select sys_context('userenv','AUTHENTICATION_DATA'      ),'AUTHENTICATION_DATA'      from dual union all
 select sys_context('userenv','AUTHENTICATION_METHOD'    ),'AUTHENTICATION_METHOD'    from dual union all
 select sys_context('userenv','BG_JOB_ID'                ),'BG_JOB_ID'                from dual union all
 select sys_context('userenv','CLIENT_IDENTIFIER'        ),'CLIENT_IDENTIFIER'        from dual union all
 select sys_context('userenv','CLIENT_INFO'              ),'CLIENT_INFO'              from dual union all
 select sys_context('userenv','CURRENT_BIND'             ),'CURRENT_BIND'             from dual union all
 select sys_context('userenv','CURRENT_EDITION_ID'       ),'CURRENT_EDITION_ID'       from dual union all
 select sys_context('userenv','CURRENT_EDITION_NAME'     ),'CURRENT_EDITION_NAME'     from dual union all
 select sys_context('userenv','CURRENT_SCHEMA'           ),'CURRENT_SCHEMA'           from dual union all
 select sys_context('userenv','CURRENT_SCHEMAID'         ),'CURRENT_SCHEMAID'         from dual union all
 select sys_context('userenv','CURRENT_SQL'              ),'CURRENT_SQL'              from dual union all
 select sys_context('userenv','CURRENT_SQL7'             ),'CURRENT_SQL7'             from dual union all
 select sys_context('userenv','CURRENT_SQL_LENGTH'       ),'CURRENT_SQL_LENGTH'       from dual union all
 select sys_context('userenv','CURRENT_USER'             ),'CURRENT_USER'             from dual union all
 select sys_context('userenv','CURRENT_USERID'           ),'CURRENT_USERID'           from dual union all
 select sys_context('userenv','DATABASE_ROLE'            ),'DATABASE_ROLE'            from dual union all
 select sys_context('userenv','DB_DOMAIN'                ),'DB_DOMAIN'                from dual union all
 select sys_context('userenv','DB_NAME'                  ),'DB_NAME'                  from dual union all
 select sys_context('userenv','DB_UNIQUE_NAME'           ),'DB_UNIQUE_NAME'           from dual union all
 select sys_context('userenv','DBLINK_INFO'              ),'DBLINK_INFO'              from dual union all
 select sys_context('userenv','ENTRYID'                  ),'ENTRYID'                  from dual union all
 select sys_context('userenv','ENTERPRISE_IDENTITY'      ),'ENTERPRISE_IDENTITY'      from dual union all
 select sys_context('userenv','FG_JOB_ID'                ),'FG_JOB_ID'                from dual union all
 select sys_context('userenv','GLOBAL_CONTEXT_MEMORY'    ),'GLOBAL_CONTEXT_MEMORY'    from dual union all
 select sys_context('userenv','GLOBAL_UID'               ),'GLOBAL_UID'               from dual union all
 select sys_context('userenv','HOST'                     ),'HOST'                     from dual union all
 select sys_context('userenv','IDENTIFICATION_TYPE'      ),'IDENTIFICATION_TYPE'      from dual union all
 select sys_context('userenv','INSTANCE'                 ),'INSTANCE'                 from dual union all
 select sys_context('userenv','INSTANCE_NAME'            ),'INSTANCE_NAME'            from dual union all
 select sys_context('userenv','IP_ADDRESS'               ),'IP_ADDRESS'               from dual union all
 select sys_context('userenv','ISDBA'                    ),'ISDBA'                    from dual union all
 select sys_context('userenv','LANG'                     ),'LANG'                     from dual union all
 select sys_context('userenv','LANGUAGE'                 ),'LANGUAGE'                 from dual union all
 select sys_context('userenv','MODULE'                   ),'MODULE'                   from dual union all
 select sys_context('userenv','NETWORK_PROTOCOL'         ),'NETWORK_PROTOCOL'         from dual union all
 select sys_context('userenv','NLS_CALENDAR'             ),'NLS_CALENDAR'             from dual union all
 select sys_context('userenv','NLS_CURRENCY'             ),'NLS_CURRENCY'             from dual union all
 select sys_context('userenv','NLS_DATE_FORMAT'          ),'NLS_DATE_FORMAT'          from dual union all
 select sys_context('userenv','NLS_DATE_LANGUAGE'        ),'NLS_DATE_LANGUAGE'        from dual union all
 select sys_context('userenv','NLS_SORT'                 ),'NLS_SORT'                 from dual union all
 select sys_context('userenv','NLS_TERRITORY'            ),'NLS_TERRITORY'            from dual union all
 select sys_context('userenv','OS_USER'                  ),'OS_USER'                  from dual union all
 select sys_context('userenv','POLICY_INVOKER'           ),'POLICY_INVOKER'           from dual union all
 select sys_context('userenv','PROXY_ENTERPRISE_IDENTITY'),'PROXY_ENTERPRISE_IDENTITY'from dual union all
 select sys_context('userenv','PROXY_USER'               ),'PROXY_USER'               from dual union all
 select sys_context('userenv','PROXY_USERID'             ),'PROXY_USERID'             from dual union all
 select sys_context('userenv','SERVER_HOST'              ),'SERVER_HOST'              from dual union all
 select sys_context('userenv','SERVICE_NAME'             ),'SERVICE_NAME'             from dual union all
 select sys_context('userenv','SESSION_EDITION_ID'       ),'SESSION_EDITION_ID'       from dual union all
 select sys_context('userenv','SESSION_EDITION_NAME'     ),'SESSION_EDITION_NAME'     from dual union all
 select sys_context('userenv','SESSION_USER'             ),'SESSION_USER'             from dual union all
 select sys_context('userenv','SESSION_USERID'           ),'SESSION_USERID'           from dual union all
 select sys_context('userenv','SESSIONID'                ),'SESSIONID'                from dual union all
 select sys_context('userenv','SID'                      ),'SID'                      from dual union all
 select sys_context('userenv','STATEMENTID'              ),'STATEMENTID'              from dual union all
 select sys_context('userenv','TERMINAL'                 ),'TERMINAL'                 from dual union all
 select sys_context('userenv','AUTHENTICATION_TYPE'      ),'AUTHENTICATION_TYPE'      from dual union all
 select sys_context('userenv','EXTERNAL_NAME'            ),'EXTERNAL_NAME'            from dual
;


Get same SQL version with extended detailed explanation of each variable:
Also see documentation posts:

No comments:

Post a Comment