Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to get hostname and IP address in Oracle

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces how to get the host name and IP address in Oracle. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Using the sys_context function, we can obtain the hostname and ip address of the current session.

SQL > select sys_context ('userenv','host') from dual

SYS_CONTEXT ('USERENV','HOST')

WORKGROUP\ IBM-L3YMBNP

SQL > select sys_context ('userenv','ip_address') from dual

SYS_CONTEXT ('USERENV','IP_ADDRESS')

127.0.0.1

Through sys_context, we can only get information about the current session. What if we want to get other session?

At this point, we use the utl_inaddr package to get

SQL > select utl_inaddr.get_host_address ('IBM-L3YMBNP') from dual

UTL_INADDR.GET_HOST_ADDRESS ('IBM-L3YMBNP')

-

9.181.142.152

And we can also get the ip of sina and other web site

SQL > select utl_inaddr.get_host_address ('www.sina.com.cn') from dual

UTL_INADDR.GET_HOST_ADDRESS ('WWW.SINA.COM.CN')

218.30.108.55

The principle is: first get the domain name resolution server (resolv.conf), according to the host.conf file to determine the resolution order, because the default is hosts file priority parsing, this time will continue to read / etc/hosts file.

If there is a parsing relationship in the hosts file, the information is returned; if it does not exist, continue to consult the DNS server to get the parsing address, and if it cannot be resolved, an error will occur.

SQL > select utl_inaddr.get_host_address ('www.a.com') from dual

Select utl_inaddr.get_host_address ('www.a.com') from dual

*

ERROR is on line 1:

ORA-29257: unknown host www.a.com

ORA-06512: in "SYS.UTL_INADDR", line 35

ORA-06512: in "SYS.UTL_INADDR", line 40

ORA-06512: in line 1

So much for sharing about how to get the host name and IP address in Oracle. I hope the above content can be of some help and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report