Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, korada.

Asked: April 05, 2002 - 3:23 pm UTC

Last updated: July 28, 2011 - 7:19 pm UTC

Version: 8.1.6

Viewed 50K+ times! This question is

You Asked

Tom,

how do i get the name of the server on which oracle is sitting.
i need this info in a stored procedure.

thanks


and Tom said...


sys@ORA817DEV.US.ORACLE.COM> select host_name from v$instance;

HOST_NAME
----------------------------------------------------------------
aria-dev

you'll need to have sys grant select on v_$instance to the owner of the procedure to put it in a proc.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

eric givler, April 05, 2002 - 8:07 pm UTC

This doesn't work with Oracle 7.3.4. You have to select machine from v$session for one of the oracle background processes.

Tom Kyte
April 06, 2002 - 11:07 am UTC

Sure -- but I always answer the question based on the version supplied -- in this case 816.

In other releases:


ops$tkyte@ORA734.WORLD> select program from v$session where program like '%(PMON)%';

PROGRAM
------------------------------------------------
oracle@aria-dev (PMON)


will work as well -- just parse out the hostname. 

How about the O/S?

Andrew, April 08, 2002 - 3:25 pm UTC

I hope this isn't off the point too much.
Is there any direct way to tell what O/S we are on? The aim would be to have one pl/sql code base for both NT and Unix. e.g. /tmp/ vs \tmp\ for ULT_FILE calls and ls vs dir for extenal O/S calls.

Tom Kyte
April 08, 2002 - 4:18 pm UTC

ops$tkyte@ORA817DEV.US.ORACLE.COM> select dbms_utility.port_string from dual;

PORT_STRING
-------------------
SVR4-be-8.1.0

would be one way -- another might be just to look at the first character of background_dump_destination:

  1  declare
  2  l_string varchar2(255);
  3  l_dummy  number;
  4  begin
  5     l_dummy := dbms_utility.get_parameter_value( 'background_dump_dest', l_dummy, l_string );
  6     dbms_output.put_line( substr( l_string, 1, 1 ) );
  7* end;
ops$tkyte@ORA817DEV.US.ORACLE.COM> /
/

PL/SQL procedure successfully completed.

since that typically is in the OS specific format with a fully qualified path. 

A reader, July 13, 2008 - 4:42 pm UTC

Tom,

I have now tried to find the hostname in an Oracle 7 database using

select program from v$session where program like '%(PMON)%';

and it didn't work because the program in that server is only showing up as "Oracle73" and some "java.exe" s. I also tried the backgound dump dest as described in one of this post's answers. In our server background dump dest doesnt have the hostname in it.

Why does the program in v$session shows only oracle73. Some other 7 servers show the hostname in it. I think in 7.1.3.2 there is not hostname in program. Do you know of any other approach where I can get the hostname in Oracle 7 database? Thank you.

Pranav Sharma, July 28, 2011 - 2:39 am UTC

I am using Oracle 10g and how do i get the server name of Oracle...??
Tom Kyte
July 28, 2011 - 7:19 pm UTC

tell me what you consider to be the "server name".

do you want the sid?
do you want the database name?
do you want the global database name?

what is your concept of a "server name", we don't really have one

Server name

krishnan, November 29, 2013 - 3:41 am UTC

I'm using oracle 10g as backend and Microsoft visual studio 2005 as frontend for my MCA mini project. While i'm connecting visual studio with oracle database, i'm getting one pop up box, in that i have to enter the server name however i'm not aware of server name. I entered the host_name but its not working. Please advice me connect with database

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library