Friday, February 17, 2012

Identifying Hostname & IP Address using SQL

UTL_INADDR is your friend. Lets see how that works.


SQL> SELECT UTL_INADDR.get_host_address  from dual;

GET_HOST_ADDRESS
--------------------------------------------------------------------------------
192.168.88.26

Or you can get any other host ip address specifying hostname as parameter

SQL> SELECT UTL_INADDR.get_host_address ('LAB_PROD') from dual;

UTL_INADDR.GET_HOST_ADDRESS('LAB_PROD')
--------------------------------------------------------------------------------
192.168.10.26

Similarly retrieve the IP address of your database box.

SQL> SELECT UTL_INADDR.get_host_name FROM dual;

GET_HOST_NAME
--------------------------------------------------------------------------------
LAB_PROD

Or you can specify any other IP address to get host name by using ip as parameter

SQL> SELECT UTL_INADDR.get_host_name('192.168.10.29') FROM dual;

UTL_INADDR.GET_HOST_NAME('192.168.10.26')
--------------------------------------------------------------------------------
LAB_DEV

No comments: