get_host_address 函数返回指定主机名的IP地址。
SQL> SELECT UTL_INADDR.get_host_address('bart') FROM dual;
UTL_INADDR.GET_HOST_ADDRESS('BART')
--------------------------------------------------------------------------------
192.168.2.4
SQL>
如果指定的主机名为NULL或省略,则返回数据库服务器的IP地址。
SQL> SELECT UTL_INADDR.get_host_address from dual;
GET_HOST_ADDRESS
--------------------------------------------------------------------------------
192.168.2.5
SQL>
如果无法识别指定的主机名,则返回错误。
SQL> SELECT UTL_INADDR.get_host_address('banana') from dual;
SELECT UTL_INADDR.get_host_address('banana') from dual
*
ERROR at line 1:
ORA-29257: host banana unknown
ORA-06512: at "SYS.UTL_INADDR", line 19
ORA-06512: at "SYS.UTL_INADDR", line 40
ORA-06512: at line 1
SQL>
get_host_name 函数返回指定IP地址的主机名。
SQL> SELECT UTL_INADDR.get_host_name('192.168.2.4') FROM dual;
UTL_INADDR.GET_HOST_NAME('192.168.2.4')
--------------------------------------------------------------------------------
bart
SQL>
如果指定的IP地址为NULL或省略,则返回数据库服务器的主机名。
SQL> SELECT UTL_INADDR.get_host_name FROM dual;
GET_HOST_NAME
--------------------------------------------------------------------------------
C4210gR2
1 row selected.
SQL>
如果无法识别指定的IP地址,则返回错误。
SQL> SELECT UTL_INADDR.get_host_name('1.1.1.1') FROM dual;
SELECT UTL_INADDR.get_host_name('1.1.1.1') FROM dual
*
ERROR at line 1:
ORA-29257: host 1.1.1.1 unknown
ORA-06512: at "SYS.UTL_INADDR", line 4
ORA-06512: at "SYS.UTL_INADDR", line 35
ORA-06512: at line 1
SQL>
SYS_CONTEXT
SYS_CONTEXT 函数能够返回当前会话的以下主机和IP地址信息:
以下示例显示了每个变量的典型输出。
SQL> SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual;
SYS_CONTEXT('USERENV','TERMINAL')
--------------------------------------------------------------------
marge
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','HOST') FROM dual;
SYS_CONTEXT('USERENV','HOST')
--------------------------------------------------------------------
marge
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual;
SYS_CONTEXT('USERENV','IP_ADDRESS')
--------------------------------------------------------------------
192.168.2.3
1 row selected.
SQL> SELECT SYS_CONTEXT('USERENV','SERVER_HOST') FROM dual;
SYS_CONTEXT('USERENV','SERVER_HOST')
--------------------------------------------------------------------
C4210gr2
1 row selected.
SQL>
V$INSTANCE
V$INSTANCE 视图的HOST_NAME列包含运行该实例的服务器的主机名。
SQL> SELECT host_name FROM v$instance;
HOST_NAME
------------------------------------------------
C4210gR2
1 row selected.
SQL>
V$SESSION
V$SESSION视图包含所有数据库会话的以下主机信息:
以下示例显示了每列的典型输出。
SQL> SELECT terminal, machine FROM v$session WHERE username = 'TIM_HALL';
TERMINAL MACHINE
------------------------------ ----------------------------------------------------
MARGE ORACLE-BASE\MARGE
1 row selected.
SQL>