Connecting Tech Pros Worldwide Forums | Help | Site Map

Determine if Schema exists

Newbie
 
Join Date: Jul 2007
Posts: 7
#1: Sep 19 '07
Hi,
I have to programmatically determine if Oracle Schema (Database) exists. Is there any query I can use for that?

e.g. in SQLSERVER 'Use myDB' would work and give me an error if myDB doesn't exists, I want to find something like that for Oracle.

Thanks for help,
NewP

debasisdas's Avatar
Moderator
 
Join Date: Dec 2006
Location: Bangalore ,India
Posts: 7,511
#2: Sep 20 '07

re: Determine if Schema exists


Do you want to check for Schema or Database ?

Because both are different from each other in oracle
Newbie
 
Join Date: Jul 2007
Posts: 7
#3: Sep 20 '07

re: Determine if Schema exists


I guess, DataBase. e.g. If I want to select records from a table, I would write,

Select * from DBNAME.TABLENAME;

This query would fail for number of reasons; two of them are
1. DBNAME doesn't exist
2. TABLENAME doesn't exist.

I want to know if DBNAME exists before writing such a query.

Thanks,
NewP
Newbie
 
Join Date: Jul 2007
Posts: 7
#4: Sep 20 '07

re: Determine if Schema exists


One solution that comes in my mind is ---

to try creating a table in the database

CREATE TABLE DBNAME.TBL1((col1 integer, col2 varchar2(20));

and this query returns error 'user DBNAME doesn't exists', if DBNAME doesn't exists.

But is there any straightforward way to know the same thing?

Thanks
NewP
Saii's Avatar
Expert
 
Join Date: Apr 2007
Posts: 141
#5: Sep 20 '07

re: Determine if Schema exists


SELECT username FROM dba_users

This will show current users on database.
Newbie
 
Join Date: Jul 2007
Posts: 7
#6: Sep 20 '07

re: Determine if Schema exists


Thank you : That works for me

NewP
Reply