【DB笔试面试500】在Oracle中,如何获取IP地址?
2021/4/15 19:58:02
本文主要是介绍【DB笔试面试500】在Oracle中,如何获取IP地址?,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在Oracle中,如何获取IP地址?
♣ 答案部分
若是获取服务器IP地址,则使用UTL_INADDR.GET_HOST_ADDRESS。若是获取客户端IP地址则使用SYS_CONTEXT('USERENV','IP_ADDRESS')。
SYS_CONTEXT函数是Oracle提供的一个获取环境上下文信息的预定义函数。该函数用来返回一个指定NAMESPACE下的PARAMETER值。该函数可以在SQL和PL/SQL语言中使用。
1SELECT SYS_CONTEXT('USERENV', 'ACTION') ACTION, 2 SYS_CONTEXT('USERENV', 'AUDITED_CURSORID') AUDITED_CURSORID, 3 SYS_CONTEXT('USERENV', 'AUTHENTICATED_IDENTITY') AUTHENTICATED_IDENTITY, 4 SYS_CONTEXT('USERENV', 'AUTHENTICATION_TYPE') AUTHENTICATION_TYPE, 5 SYS_CONTEXT('USERENV', 'AUTHENTICATION_DATA') AUTHENTICATION_DATA, 6 SYS_CONTEXT('USERENV', 'AUTHENTICATION_METHOD') AUTHENTICATION_METHOD, 7 SYS_CONTEXT('USERENV', 'BG_JOB_ID') BG_JOB_ID, 8 SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') CLIENT_IDENTIFIER, 9 SYS_CONTEXT('USERENV', 'CLIENT_INFO') CLIENT_INFO, --USERENV('CLIENT_INFO') 10 SYS_CONTEXT('USERENV', 'CURRENT_BIND') CURRENT_BIND, 11 SYS_CONTEXT('USERENV', 'CURRENT_EDITION_ID') CURRENT_EDITION_ID, 12 SYS_CONTEXT('USERENV', 'CURRENT_EDITION_NAME') CURRENT_EDITION_NAME, 13 SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA') CURRENT_SCHEMA, 14 SYS_CONTEXT('USERENV', 'CURRENT_SCHEMAID') CURRENT_SCHEMAID, 15 SYS_CONTEXT('USERENV', 'CURRENT_SQL') CURRENT_SQL, 16 SYS_CONTEXT('USERENV', 'CURRENT_SQLN') CURRENT_SQLN, 17 SYS_CONTEXT('USERENV', 'CURRENT_SQL_LENGTH') CURRENT_SQL_LENGTH, 18 SYS_CONTEXT('USERENV', 'CURRENT_USER') CURRENT_USER, 19 SYS_CONTEXT('USERENV', 'CURRENT_USERID') CURRENT_USERID, 20 SYS_CONTEXT('USERENV', 'DATABASE_ROLE') DATABASE_ROLE, 21 SYS_CONTEXT('USERENV', 'DB_DOMAIN') DB_DOMAIN, 22 SYS_CONTEXT('USERENV', 'DB_NAME') DB_NAME, 23 SYS_CONTEXT('USERENV', 'DB_UNIQUE_NAME') DB_UNIQUE_NAME, 24 SYS_CONTEXT('USERENV', 'DBLINK_INFO') DBLINK_INFO, 25 SYS_CONTEXT('USERENV', 'ENTRYID') ENTRYID, --USERENV('ENTRYID') 26 SYS_CONTEXT('USERENV', 'ENTERPRISE_IDENTITY') ENTERPRISE_IDENTITY, 27 SYS_CONTEXT('USERENV', 'EXTERNAL_NAME') EXTERNAL_NAME, 28 SYS_CONTEXT('USERENV', 'FG_JOB_ID') FG_JOB_ID, 29 SYS_CONTEXT('USERENV', 'GLOBAL_CONTEXT_MEMORY') GLOBAL_CONTEXT_MEMORY, 30 SYS_CONTEXT('USERENV', 'GLOBAL_UID') GLOBAL_UID, 31 SYS_CONTEXT('USERENV', 'HOST') HOST, -- USERENV('TERMINAL') 32 SYS_CONTEXT('USERENV', 'IDENTIFICATION_TYPE') IDENTIFICATION_TYPE, 33 SYS_CONTEXT('USERENV', 'INSTANCE') INSTANCE, --USERENV('INSTANCE') 34 SYS_CONTEXT('USERENV', 'INSTANCE_NAME') INSTANCE_NAME, 35 SYS_CONTEXT('USERENV', 'IP_ADDRESS') IP_ADDRESS, --ORA_CLIENT_IP_ADDRESS 36 SYS_CONTEXT('USERENV', 'ISDBA') ISDBA, --USERENV('ISDBA') 37 SYS_CONTEXT('USERENV', 'LANG') LANG, --USERENV('LANG') 38 SYS_CONTEXT('USERENV', 'LANGUAGE') LANGUAGE, --USERENV('LANGUAGE'), 39 SYS_CONTEXT('USERENV', 'MODULE') MODULE, 40 SYS_CONTEXT('USERENV', 'NETWORK_PROTOCOL') NETWORK_PROTOCOL, 41 SYS_CONTEXT('USERENV', 'NLS_CALENDAR') NLS_CALENDAR, 42 SYS_CONTEXT('USERENV', 'NLS_CURRENCY') NLS_CURRENCY, 43 SYS_CONTEXT('USERENV', 'NLS_DATE_FORMAT') NLS_DATE_FORMAT, 44 SYS_CONTEXT('USERENV', 'NLS_DATE_LANGUAGE') NLS_DATE_LANGUAGE, 45 SYS_CONTEXT('USERENV', 'NLS_SORT') NLS_SORT, 46 SYS_CONTEXT('USERENV', 'NLS_TERRITORY') NLS_TERRITORY, 47 SYS_CONTEXT('USERENV', 'OS_USER') OS_USER, 48 SYS_CONTEXT('USERENV', 'POLICY_INVOKER') POLICY_INVOKER, 49 SYS_CONTEXT('USERENV', 'PROXY_ENTERPRISE_IDENTITY') PROXY_ENTERPRISE_IDENTITY, 50 SYS_CONTEXT('USERENV', 'PROXY_USER') PROXY_USER, 51 SYS_CONTEXT('USERENV', 'PROXY_USERID') PROXY_USERID, 52 SYS_CONTEXT('USERENV', 'SERVER_HOST') SERVER_HOST, 53 SYS_CONTEXT('USERENV', 'SERVICE_NAME') SERVICE_NAME, 54 SYS_CONTEXT('USERENV', 'SESSION_EDITION_ID') SESSION_EDITION_ID, 55 SYS_CONTEXT('USERENV', 'SESSION_EDITION_NAME') SESSION_EDITION_NAME, 56 SYS_CONTEXT('USERENV', 'SESSION_USER') SESSION_USER, --ORA_LOGIN_USER 57 SYS_CONTEXT('USERENV', 'SESSION_USERID') SESSION_USERID, 58 SYS_CONTEXT('USERENV', 'SESSIONID') SESSIONID, -- USERENV('SESSIONID') , V$SESSION.AUDSID 59 SYS_CONTEXT('USERENV', 'SID') SID, 60 SYS_CONTEXT('USERENV', 'STATEMENTID') STATEMENTID, 61 SYS_CONTEXT('USERENV', 'TERMINAL') TERMINAL --USERENV('TERMINAL') 62 FROM DUAL;
USERENV函数用来返回当前的会话信息,常用的有如下信息:
1SELECT USERENV('CLIENT_INFO') CLIENT_INFO, 2 USERENV('LANGUAGE') 数据库字符集, 3 USERENV('ISDBA') 是否DBA角色, 4 USERENV('SESSIONID') 当前会话标识符, 5 USERENV('ENTRYID') 可审计的会话标识符, 6 USERENV('LANG') 会话语言名称的ISO简记, 7 USERENV('INSTANCE') 当前的实例, 8 USERENV('TERMINAL') 当前计算机名 9 FROM DUAL;
这篇关于【DB笔试面试500】在Oracle中,如何获取IP地址?的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-29从 Elastic 迁移到 Easysearch 指引
- 2024-12-29uni-app 中使用 Vant Weapp,怎么安装和配置npm ?-icode9专业技术文章分享
- 2024-12-27Nacos多环境配置学习入门
- 2024-12-27Nacos快速入门学习入门
- 2024-12-27Nacos快速入门学习入门
- 2024-12-27Nacos配置中心学习入门指南
- 2024-12-27Nacos配置中心学习入门
- 2024-12-27Nacos做项目隔离学习入门
- 2024-12-27Nacos做项目隔离学习入门
- 2024-12-27Nacos初识学习入门:轻松掌握服务发现与配置管理