tags:

views:

259

answers:

2

Is there a way of finding the name of the server an Oracle database is hosted on from PL/SQL?

+4  A: 
SELECT  host_name
FROM    v$instance
Quassnoi
Technically, as multiple servers can mount an Oracle database, `select host_name from gv$instance` would return all hosts. The query above does show the host you're currently connected to in that session, however.
Adam Musch
+6  A: 

If you don't have access to the v$ views (as suggested by Quassnoi) there are two alternatives

select utl_inaddr.get_host_name from dual

and

select sys_context('USERENV','SERVER_HOST') from dual

Personally I'd tend towards the last as it doesn't require any grants/privileges which makes it easier from stored procedures.

Gary
+1 for `sys_context()` as the easiest and most appropriate solution.
APC