In Oracle, it is possible to get a database server host name using a simple SQL query.
In this note i will show how to SELECT
the Oracle database server host name you’re currently connected to, using the SQL query that doesn’t require any special permissions.
I will also show how to get the database name, the current schema/user and the name and IP address of the host machine from which the client has connected.
Cool Tip: Show Oracle “databases” (schemas/users) – equivalent to SHOW DATABASES
command in MySQL! Read more →
Oracle Server Name
Display a server host name of the Oracle database you’re currently connected to:
SQL> SELECT sys_context('USERENV','SERVER_HOST') server_host FROM dual;
You may find the query below useful as well, as besides of the server host name it displays the database name, the current schema/user, and the name and IP address of the host machine from which the client has connected:
SQL> SELECT sys_context ('USERENV','db_name') db_name, sys_context ('USERENV','server_host') server_host, sys_context ('USERENV','current_schema') current_schema, sys_context ('USERENV','session_user') current_user, sys_context ('USERENV','host') client_host, sys_context ('USERENV','ip_address') client_ip_address FROM dual;