Determine if Schema exists

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newP
    New Member
    • Jul 2007
    • 7

    Determine if Schema exists

    Hi,
    I have to programmaticall y 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
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Do you want to check for Schema or Database ?

    Because both are different from each other in oracle

    Comment

    • newP
      New Member
      • Jul 2007
      • 7

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

      Select * from DBNAME.TABLENAM E;

      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

      Comment

      • newP
        New Member
        • Jul 2007
        • 7

        #4
        One solution that comes in my mind is ---

        to try creating a table in the database

        CREATE TABLE DBNAME.TBL1((co l1 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

        Comment

        • Saii
          Recognized Expert New Member
          • Apr 2007
          • 145

          #5
          SELECT username FROM dba_users

          This will show current users on database.

          Comment

          • newP
            New Member
            • Jul 2007
            • 7

            #6
            Thank you : That works for me

            NewP

            Comment

            Working...