程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle數據庫基礎 >> Oracle中獲取會話信息的兩個函數使用教程

Oracle中獲取會話信息的兩個函數使用教程

編輯:Oracle數據庫基礎
  這篇文章主要介紹了Oracle中獲取會話信息的兩個函數分享,本文分別講解了USERENV和兩個函數sys_context,並對可以獲取哪些信息作了介紹,需要的朋友可以參考下

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;
 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved