Oracle gives you a number of ways to know the name of the database you are connected to, from inside a SQL*Plus session. Here are three ways to find out your Oracle database name.
Through V$DATABASE
SQL> select name from V$database; NAME --------- XE
The above will work only if your login has access to V$DATABASE. This is generally accessible to DBA logins only. For non-DBA logins, you may need to grant SELECT on V$ views.
In case access to V$DATABASE cannot be granted to you, use one of the two publicly accessible methods below.
Through GLOBAL_NAME
GLOBAL_NAME has the default value of db_name + db_domain. This is publicly accessible to anyone logged in to the database.
SQL> SQL> select * from global_name; GLOBAL_NAME -------------------------------------- XE
Through dbms_utility.get_parameter_value
The function get_parameter_value in dbms_utility returns the value of a given init.ora parameter. In this case the parameter is DB_NAME
SQL> variable i number SQL> variable dbname varchar2(30); SQL> SQL> begin 2 :i:=dbms_utility.get_parameter_value('db_name',:i,:dbname); 3 end; 4 / PL/SQL procedure successfully completed. SQL> print dbname DBNAME ------------------------------------------------------ XE
Summary
Oracle gives you easy ways to find out your Oracle database name from inside a SQL*Plus session. This article demonstrates three ways, using:
- V$DATABASE
- GLOBAL_NAME
- DBMS_UTILITY.GET_PARAMETER_VALUE
Similarly, here’s how to find your Oracle database version.
{ 4 comments… read them below or add one }
Very useful, thank you!
Consider you have configured multiple database on a server . How to view all these database name ?
Thank you very much 🙂
Thank you