How to Query Database Name in Oracle SQL Developer?

Xonatron picture Xonatron · Jan 23, 2012 · Viewed 222.3k times · Source

How do I query the database name in Oracle SQL Developer? I have tried the following and they all fail:

SELECT DB_NAME();

SELECT DATABASE();

Why do these basic MySQL queries fail in SQL Developer? Even this one fails too:

show tables;

EDIT: I can connect to the database and run queries such as:

select * from table_name_here;

EDIT 2: The database type is Oracle, this is why MySQL queries are failing. I thought it was related to the database client not the database itself. I was wrong. I'll leave the question as is for other as lost as I was.

Answer

Xonatron picture Xonatron · Jan 24, 2012

Once I realized I was running an Oracle database, not MySQL, I found the answer

select * from v$database;

or

select ora_database_name from dual;

Try both. Credit and source goes to: http://www.perlmonks.org/?node_id=520376.