How to display databases in Oracle 11g using SQL*Plus

468,795

Solution 1

You can think of a MySQL "database" as a schema/user in Oracle. If you have the privileges, you can query the DBA_USERS view to see the list of schemas:

SELECT * FROM DBA_USERS;

Solution 2

SELECT NAME FROM v$database; shows the database name in oracle

Solution 3

Oracle does not have a simple database model like MySQL or MS SQL Server. I find the closest thing is to query the tablespaces and the corresponding users within them.

For example, I have a DEV_DB tablespace with all my actual 'databases' within them:

SQL> SELECT TABLESPACE_NAME FROM USER_TABLESPACES;

Resulting in:

SYSTEM
SYSAUX
UNDOTBS1
TEMP
USERS
EXAMPLE
DEV_DB

It is also possible to query the users in all tablespaces:

SQL> select USERNAME, DEFAULT_TABLESPACE from DBA_USERS;

Or within a specific tablespace (using my DEV_DB tablespace as an example):

SQL> select USERNAME, DEFAULT_TABLESPACE from DBA_USERS where DEFAULT_TABLESPACE = 'DEV_DB';

ROLES DEV_DB
DATAWARE DEV_DB
DATAMART DEV_DB
STAGING DEV_DB

Solution 4

Maybe you could use this view, but i'm not sure.

select * from v$database;

But I think It will only show you info about the current db.

Other option, if the db is running in linux... whould be something like this:

SQL>!grep SID $TNS_ADMIN/tnsnames.ora | grep -v PLSExtProc

Solution 5

I am not clearly about it but typically one server has one database (with many users), if you create many databases mean that you create many instances, listeners, ... as well. So you can check your LISTENER to identify it.

In my testing I created 2 databases (dbtest and dbtest_1) so when I check my LISTENER status it appeared like this:

lsnrctl status

....

STATUS of the LISTENER

.....

(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=10.10.20.20)(PORT=1521)))

Services Summary...

Service "dbtest" has 1 instance(s).

Instance "dbtest", status READY, has 1 handler(s) for this service...

Service "dbtest1XDB" has 1 instance(s).

Instance "dbtest1", status READY, has 1 handler(s) for this service...

Service "dbtest_1" has 1 instance(s).

Instance "dbtest1", status READY, has 1 handler(s) for this service... The command completed successfully

Share:
468,795
Nubkadiya
Author by

Nubkadiya

Updated on October 25, 2020

Comments

  • Nubkadiya
    Nubkadiya over 3 years

    With help of this command show databases; I can see databases in MySQL.

    How to show the available databases in Oracle?

  • Gary Myers
    Gary Myers almost 14 years
    Some oracle databases have a lot of users without objects. For these, and alternative is SELECT DISTINCT OWNER FROM ALL_OBJECTS;
  • dpbradley
    dpbradley almost 14 years
    +1 nice alternative, just be aware that if you are not a privileged user and issue this query, you will see only those OWNER's where you have a privilege on at least one of their objects.
  • a1an
    a1an almost 12 years
    First one not working in 11g: "ORA-00942: table or view does not exist"
  • a1an
    a1an almost 12 years
    Query to DBA_USERS gives a "ORA-00942: table or view does not exist", maybe permission issue? The one in the comment "SELECT DISTINCT OWNER FROM ALL_OBJECTS;" is working with same access credentials. db 11g
  • Jonathan
    Jonathan almost 12 years
    Hi @a1an. Without doubt, v$database exists in 11g. Check if you're executing the query with rights enought. Here you have the documentation about v$database for oracle 11g. docs.oracle.com/cd/B28359_01/server.111/b28320/… Algo, here you have a post with an example about the use of v%database in oracle 11g. neeraj-dba.blogspot.com.es/2011/10/… Good Luck!
  • a1an
    a1an almost 12 years
    Probably jsut a permissions issue, executing it as sysdba works
  • Jonathan
    Jonathan almost 12 years
    Ok @a1an, just give permissions for select on that view. grant select on v_$database to youruser; PLEASE NOTE the underscore! v$database is a synonym and you can't grant proviledgest for synonyms (It can end in a ORA-02030 error).
  • Randy Stegbauer
    Randy Stegbauer over 9 years
    I think that this is what the question was asking. Or at least this is what I think of when I hear "database"...as opposed to schema (or user).
  • Felipe Augusto
    Felipe Augusto about 6 years
    SELECT * FROM DBA_USERS;
  • Ameya Deshpande
    Ameya Deshpande over 5 years
    this should be the answer
  • Álvaro González
    Álvaro González over 4 years
    If e.g. you run Oracle Database Express Edition this prints something like XE, i.e. the unique name that uniquely identifies your instance/database (is it called SID?). On the other side, MySQL's show databases command prints what MySQL calls database aka schema (roughly what you get with SELECT USERNAME FROM DBA_USERS in Oracle).