Oracle中获取会话信息的两个函数分享
网络编程 2021-07-05 16:08www.168986.cn编程入门
这篇文章主要介绍了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') work_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') work_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;
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程