Find server IP using sql

Find server IP using SQL Query

Hello, friends in this article we going to discuss how to find server IP or Hostname using SQL query.

How to check hostname using SQL query in oracle?

The following query will show the hostname where you’re currently connected to in that session.

How to Convert Non-CDB Database into CDB Database Click here?

SQL> SELECT  host_name FROM v$instance;

The above query will work only for a single instance, if you are connected on multi-instances then use the following query to check the all the hostnames.

SQL> SELECT  host_name FROM gv$instance;

In case, If you don’t have access to the v$ views, there are two alternatives. You can get it from the dual table using the below queries.

SQL> select utl_inaddr.get_host_name from dual; 

 OR 

 SQL> select sys_context('USERENV','SERVER_HOST') from dual;  

sys_context() as the easiest and most appropriate solution. The only reason not to use sys_context is that it lower cases the name, which the above 2 don’t.

सौभाग्य योजना के तहत मुफ्त बिजली कनैक्शन कैसे ले पूरी जानकारी हिंदी में?

Find server IP using SQL

You can use sys_context(‘USERENV‘, ‘SERVICE_NAME‘) to get the database service name instead of the machine name. Use the below query to find complete details.

SQL> select sys_context ( 'USERENV', 'DB_NAME' ) db_name,
          sys_context ( 'USERENV', 'SESSION_USER' ) user_name,
          sys_context ( 'USERENV', 'SERVER_HOST' ) db_host,
          sys_context ( 'USERENV', 'HOST' ) user_host
         from dual;

Hop you fond this article useful, please share your review in comment section below.

Share

1 thought on “Find server IP using SQL Query”

Leave a Comment

Share