Home » SQL & PL/SQL » SQL & PL/SQL » how to get database name
how to get database name [message #28806] Thu, 22 January 2004 09:33 Go to next message
Kumar
Messages: 115
Registered: December 1998
Senior Member
i need to get the name of the database i am connected to. what should be the sql statement for this

thanks
Re: how to get database name [message #28807 is a reply to message #28806] Thu, 22 January 2004 10:35 Go to previous messageGo to next message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
 Select name from v$database;
 select sys_context('USERENV','DB_NAME') from dual;
 select global_name from global_name; 
 -- Global name need not be the same as your database name, but it usually is.
 select value from v$parameter where name='db_name';
 select value from v$system_parameter where name='db_name';
 select value from v$spparameter  where name='db_name';



are some of the ways..

-Thiru
Re: how to get database name [message #28825 is a reply to message #28807] Fri, 23 January 2004 14:11 Go to previous messageGo to next message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
If your database only has one instance (the usual case) then this one is good too:
Select instance_name from v$instance;

Beware of reading global_name - If the DBA clones one DB from another and forgets to change the global_name, then it will have the value of the database it was cloned from.
Re: how to get database name [message #28826 is a reply to message #28825] Fri, 23 January 2004 15:58 Go to previous message
Thiru
Messages: 1089
Registered: May 2002
Senior Member
Instance name is not the same as database name ,although it is usually the same.

And for global_name,ofcourse! "Beware of reading global_name" !

also read my earlier post regarding global_name -->Global_name

[Updated on: Fri, 18 February 2005 23:32]

Report message to a moderator

Previous Topic: Relation between Connection and Session
Next Topic: SQL server or ORACLE
Goto Forum:
  


Current Time: Mon Sep 01 10:12:57 CDT 2025