Devashri B.
Devashri B.

Reputation: 2703

What is the difference between ora_database_name and sys_context('userenv','service_name')

What is the difference between ora_database_name and sys_context('userenv','service_name'). Both the queries below gives different results.

select ora_database_name  from dual;
select sys_context('userenv','service_name') from dual;

How and where to find actual database name?

Upvotes: 3

Views: 2604

Answers (1)

wolφi
wolφi

Reputation: 8361

ora_database_name is a synonym to the package function dbms_standard.database_name. I suspect it is identical to

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

However, sys_context('userenv','service_name') is the service name you are currently using.

A database can support more than one service name. To see the list:

SELECT name FROM all_services;
orclpdb1

You can add additional services ...

EXEC DBMS_SERVICE.CREATE_SERVICE('myservice', 'myservice');
EXEC DBMS_SERVICE.START_SERVICE('myservice', NULL);

SELECT name FROM all_services;
orclpdb1
myservice

... which can then be used to connect to the database ...

sqlplus user/pass@myhost:1521/myservice

Upvotes: 2

Related Questions