Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Name of database connected to 1

Status
Not open for further replies.

BJCooperIT

Programmer
May 30, 2002
1,210
0
0
US
I have a function in a package that returns the name of the database to which a session is connected by returning GLOBAL_NAME. This has worked well for the past three years. When a testing script is run, the database, date, time and description are displayed:
Code:
HSDEV      04/09/2009 03:41:28pm     Test INTERNET_STATUS
The database names HSDEV, HSSTAGE, HSPROD have always reflected the database in which the test was run.

We have a new 10g database and we connect to HSDEV.HP. My problem is that the name of this database is returned as HSDEV, not HSDEV.HP:
Code:
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 
Connected as devbjc
 
SQL> select global_name from global_name;
 
GLOBAL_NAME
--------------------
HSDEV.WORLD
 
SQL> select ora_database_name from dual;
 
ORA_DATABASE_NAME
--------------------
HSDEV.WORLD
 
SQL> select sys_context('userenv','db_name') from dual;
 
SYS_CONTEXT('USERENV','DB_NAME
-------------------------------
hsdev
 
SQL>
The function no longer properly identified where the test was run. So I have modified the function to append the version number (extracted from the BANNER column in SYS.V_$VERSION) which helped:
Code:
HSDEV 10.2     04/09/2009 03:45:16pm     Test INTERNET_STATUS
But, the proper way would be to display the database name to which I connect (HSDEV.HP). Any help you can offer is much appreciated.

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~ George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
 
May well be too simplistic, but you have renamed the database with alter database rename global_name to HSDEV.HP;?

Some days are diamonds, some days are rocks - make sure most are the former.
 
Here I am just a developer without those kinds of privileges. When I inquired about it, the answer I received from the state DBAs is that the name must be identical for migration purposes.

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~ George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
 

You are getting the expected results, I don't know why would you expect "HSDEV.HP"?

Oracle® Database Administrator's Guide said:
The global database name consists of the user-specified local database name and the location of the database within a network structure. The DB_NAME initialization parameter determines the local name component of the database name, and the DB_DOMAIN parameter indicates the domain (logical location) within a network structure. The combination of the settings for these two parameters must form a database name that is unique within a network.
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 


PS: Perhaps the GLOBAL_NAME was set incorrectly in the previous database or the "DOMAIN_NAME" was set to HP instead of WORLD.
[ponder]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Not that I expect it, it is what I need for literally hundreds of testing scripts to be self-documenting.

It sounds like what I might need is the DB_DOMAIN and DB_NAME parameter values. Is there a way for me to be able to select those values to create the actual database name we connect to?

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~ George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
 

GLOBAL_NAME should be: {db_name}.{db_domain}

If you are getting HSDEV.WORLD that means the db_domain name is set to "WORLD"

To get the result you want, you would need to change db_domain to HP and GLOBAL_NAME to HSDEV.HP

If you actually "connect" to HSDEV.HP It may be perhaps the database "alias" in tnsnamea.ora is set to {db_name}.{hostname}, you could then try the following:
Code:
Select sys_context('USERENV','SERVER_HOST') from dual;
:p




----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Thanks for trying again. I don't have privileges to change any parameters. The server host yields yet another name:
Code:
SQL> Select substr(sys_context('USERENV','SERVER_HOST'),1,30) server_host from dual;
 
SERVER_HOST
------------------------------
ofw1
 
SQL>
Seems like it shouldn't be this difficult. If I connect to that name, surely I should be able to recreate it. Sigh...

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~ George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
 

Where does (did) the "HP" come from?
[ponder]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Saucy! :)

Hewlett Packard perhaps?

Some days are diamonds, some days are rocks - make sure most are the former.
 
No idea. The DBAs are referring to the 10g database as the HP database. Maybe I can decode the version number into HP for my purposes. Thanks for trying though - I did learn a bit and will tuck that knowledge away.

[sup]Beware of false knowledge; it is more dangerous than ignorance.[/sup][sup] ~ George Bernard Shaw[/sup]
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top