察看當前Session登入的資料庫

adian發表於2007-06-12
察看當前Session登入的資料庫[@more@]如果可以訪問V$表,可以透過
select instance_name, version from v$instance;

如果沒有相關許可權,也可以透過SYS_CONTEXT得到Session登入的資料庫。
select SYS_CONTEXT('USERENV' ,'DB_NAME') db_name from dual;

透過sys_context( namespace, parameter, [ length ] ),可以獲取Oracle相關的環境資訊。如果需要得到當前session的Oracle相關資訊,在namespace的引數值為'USERENV'。還可以透過userenv函式來獲取當前session的Oracle相關資訊,這是一個遺留函式,Oracle推薦使用sys_context來獲取。DBMS_SESSION.set_context設定parameter的值。
select SYS_CONTEXT('USERENV' ,'TERMINAL') terminal from dual;
select SYS_CONTEXT('USERENV' ,'LANGUAGE') language from dual;
select SYS_CONTEXT('USERENV' ,'SESSIONID') sessionid from dual;
select SYS_CONTEXT('USERENV' ,'INSTANCE') instance from dual;
select SYS_CONTEXT('USERENV' ,'ENTRYID') entryid from dual;
select SYS_CONTEXT('USERENV' ,'ISDBA') isdba from dual;
select SYS_CONTEXT('USERENV' ,'NLS_TERRITORY') nls_territory from dual;
select SYS_CONTEXT('USERENV' ,'NLS_CURRENCY') nls_currency from dual;
select SYS_CONTEXT('USERENV' ,'NLS_CALENDAR') nls_calendar from dual;
select SYS_CONTEXT('USERENV' ,'NLS_DATE_FORMAT') nls_date_format from dual;
select SYS_CONTEXT('USERENV' ,'NLS_DATE_LANGUAGE') nls_date_language from dual;
select SYS_CONTEXT('USERENV' ,'NLS_SORT') nls_sort from dual;
select SYS_CONTEXT('USERENV' ,'CURRENT_USER') current_user from dual;
select SYS_CONTEXT('USERENV' ,'CURRENT_USERID') current_userid from dual;
select SYS_CONTEXT('USERENV' ,'SESSION_USER') session_user from dual;
select SYS_CONTEXT('USERENV' ,'SESSION_USERID') session_userid from dual;
select SYS_CONTEXT('USERENV' ,'PROXY_USER') proxy_user from dual;
select SYS_CONTEXT('USERENV' ,'PROXY_USERID') proxy_userid from dual;
select SYS_CONTEXT('USERENV' ,'DB_DOMAIN') db_domain from dual;
select SYS_CONTEXT('USERENV' ,'DB_NAME') db_name from dual;
select SYS_CONTEXT('USERENV' ,'HOST') host from dual;
select SYS_CONTEXT('USERENV' ,'OS_USER') os_user from dual;
select SYS_CONTEXT('USERENV' ,'EXTERNAL_NAME') external_name from dual;
select SYS_CONTEXT('USERENV' ,'IP_ADDRESS') ip_address from dual;
select SYS_CONTEXT('USERENV' ,'NETWORK_PROTOCOL') network_protocol from dual;
select SYS_CONTEXT('USERENV' ,'BG_JOB_ID') bg_job_id from dual;
select SYS_CONTEXT('USERENV' ,'FG_JOB_ID') fg_job_id from dual;
select SYS_CONTEXT('USERENV' ,'AUTHENTICATION_TYPE') authentication_type from dual;
select SYS_CONTEXT('USERENV' ,'AUTHENTICATION_DATA') authentication_data from dual;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/94829/viewspace-918578/,如需轉載,請註明出處,否則將追究法律責任。

相關文章