Link to home
Start Free TrialLog in
Avatar of sollala
sollala

asked on

How to find database name?

I know oracle provides database_name function (actually it is "dbms_standard.database_name") to get database name.

But this function may not installed on server by default, does any one know other way of finding database name?
Avatar of Danielzt
Danielzt

select * from sys.v_$database

select * from sys.v_$database where name='db_name'

tnsnames.ora
init.ora

windows: registry
HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE

UNIX: $env  
look for ORACLE_SID





Avatar of sollala

ASKER

I need sql query, not from env. Above sql query will not work for normal user, needs dba access
create a view that contains info from v$database and grant select for that user.

Hope it helps.
Avatar of sollala

ASKER

My application will run on any DB and will not have DBA access to modify grants.
ASKER CERTIFIED SOLUTION
Avatar of asimkovsky
asimkovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try this:

select global_name from global_name;
1).Open init.ora initialization parameter file
and check db_name= "          "
parameter this will tell u the database name.

or check this query

2) connect sys/change_on_install;
   select name from v$database;

Hope this will help

Fayyaz
Try this

select sys_context('userenv','db_name') from dual;

With warm regards
Rashid
all these things that have been said before work fine for users without any privileges:
select ora_database_name from dual;
select sys_context('userenv','db_name') from dual;
select global_name from global_name;

however, I don't understand the starting point of the question. dbms_standard should always be available in the database, it's created in dbmsstdx.sql which is one of the first things called by catproc.sql which should always have been run when the database was created.
If dbms_standard is not available, not being able to find out the database name should not be your greatest worry.