欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Oracle中获取会话信息的两个函数分享

程序员文章站 2023-01-23 09:52:28
1、 userenv(option)    返回当前的会话信息.    option='isdba'若当前是dba角色,则为true,否则fal...

1、 userenv(option) 
  返回当前的会话信息. 
  option='isdba'若当前是dba角色,则为true,否则false. 
  option='language'返回数据库的字符集. 
  option='sessionid'为当前会话标识符. 
  option='entryid'返回可审计的会话标识符. 
  option='lang'返回会话语言名称的iso简记. 
  option='instance'返回当前的实例. 
    option='terminal'返回当前计算机名 
  select userenv('language') from dual;
2、sys_context

复制代码 代码如下:

select  
sys_context('userenv','terminal') terminal,  
sys_context('userenv','language') language,  
sys_context('userenv','sessionid') sessionid,  
sys_context('userenv','instance') instance,  
sys_context('userenv','entryid') entryid,  
sys_context('userenv','isdba') isdba,  
sys_context('userenv','nls_territory') nls_territory,  
sys_context('userenv','nls_currency') nls_currency,  
sys_context('userenv','nls_calendar') nls_calendar,  
sys_context('userenv','nls_date_format') nls_date_format,  
sys_context('userenv','nls_date_language') nls_date_language,  
sys_context('userenv','nls_sort') nls_sort,  
sys_context('userenv','current_user') current_user,  
sys_context('userenv','current_userid') current_userid,  
sys_context('userenv','session_user') session_user,  
sys_context('userenv','session_userid') session_userid,  
sys_context('userenv','proxy_user') proxy_user,  
sys_context('userenv','proxy_userid') proxy_userid,  
sys_context('userenv','db_domain') db_domain,  
sys_context('userenv','db_name') db_name,  
sys_context('userenv','host') host,  
sys_context('userenv','os_user') os_user,  
sys_context('userenv','external_name') external_name,  
sys_context('userenv','ip_address') ip_address,  
sys_context('userenv','network_protocol') network_protocol,  
sys_context('userenv','bg_job_id') bg_job_id,  
sys_context('userenv','fg_job_id') fg_job_id,  
sys_context('userenv','authentication_type') authentication_type,  
sys_context('userenv','authentication_data') authentication_data  
from dual

3.与系统视图v$session组合使用可以获得更多信息(客户端所使用的应用程序等)
复制代码 代码如下:

select *
  from v$session se,
       (select sys_context('userenv', 'terminal') terminal,
               sys_context('userenv', 'language') language,
               sys_context('userenv', 'sessionid') sessionid,
               sys_context('userenv', 'instance') instance,
               sys_context('userenv', 'entryid') entryid,
               sys_context('userenv', 'isdba') isdba,
               sys_context('userenv', 'nls_territory') nls_territory,
               sys_context('userenv', 'nls_currency') nls_currency,
               sys_context('userenv', 'nls_calendar') nls_calendar,
               sys_context('userenv', 'nls_date_format') nls_date_format,
               sys_context('userenv', 'nls_date_language') nls_date_language,
               sys_context('userenv', 'nls_sort') nls_sort,
               sys_context('userenv', 'current_user') current_user,
               sys_context('userenv', 'current_userid') current_userid,
               sys_context('userenv', 'session_user') session_user,
               sys_context('userenv', 'session_userid') session_userid,
               sys_context('userenv', 'proxy_user') proxy_user,
               sys_context('userenv', 'proxy_userid') proxy_userid,
               sys_context('userenv', 'db_domain') db_domain,
               sys_context('userenv', 'db_name') db_name,
               sys_context('userenv', 'host') host,
               sys_context('userenv', 'os_user') os_user,
               sys_context('userenv', 'external_name') external_name,
               sys_context('userenv', 'ip_address') ip_address,
               sys_context('userenv', 'network_protocol') network_protocol,
               sys_context('userenv', 'bg_job_id') bg_job_id,
               sys_context('userenv', 'fg_job_id') fg_job_id,
               sys_context('userenv', 'authentication_type') authentication_type,
               sys_context('userenv', 'authentication_data') authentication_data
          from dual) base
 where se.audsid = base.sessionid;