to check if a table exists

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DottingTheNet

    to check if a table exists

    i promise no more silly questions after this

    but how do i check if a table exists??
    it is my understanding that the exists can only be used in the where
    clause of the query.
    i just want s'thing simple like
    if exists ('test')
    then ---good
    else
    --create it
    end if;
    thanx in advance!!!
  • Douglas Hawthorne

    #2
    Re: to check if a table exists

    "DottingThe Net" <dottingthenet@ hotmail.comwrot e in message
    news:11bf8d5a.0 404112139.78b6b 18e@posting.goo gle.com...
    i promise no more silly questions after this
    >
    but how do i check if a table exists??
    it is my understanding that the exists can only be used in the where
    clause of the query.
    i just want s'thing simple like
    if exists ('test')
    then ---good
    else
    --create it
    end if;
    thanx in advance!!!
    Check out the ALL_TABLES and USER_TABLES views in the "Database Reference"
    manual.

    Douglas Hawthorne


    Comment

    • Mark D Powell

      #3
      Re: to check if a table exists

      "Douglas Hawthorne" <douglashawthor ne@yahoo.com.au wrote in message news:<nvqec.521 2$ED.3499@news-server.bigpond. net.au>...
      "DottingThe Net" <dottingthenet@ hotmail.comwrot e in message
      news:11bf8d5a.0 404112139.78b6b 18e@posting.goo gle.com...
      i promise no more silly questions after this

      but how do i check if a table exists??
      it is my understanding that the exists can only be used in the where
      clause of the query.
      i just want s'thing simple like
      if exists ('test')
      then ---good
      else
      --create it
      end if;
      thanx in advance!!!
      >
      Check out the ALL_TABLES and USER_TABLES views in the "Database Reference"
      manual.
      >
      Douglas Hawthorne
      Something like
      begin
      select table_name into v_variable from all_tables
      where owner = v_owner and table_name = v_table_name
      -- found logic here
      exception
      when no_Data_found then ... execute immediate create logic
      end;

      You can probably find a working example/stored function in the archives.

      HTH -- Mark D Powell --

      Comment

      • sybrandb@yahoo.com

        #4
        Re: to check if a table exists

        dottingthenet@h otmail.com (DottingTheNet) wrote in message news:<11bf8d5a. 0404112139.78b6 b18e@posting.go ogle.com>...
        i promise no more silly questions after this
        >
        but how do i check if a table exists??
        it is my understanding that the exists can only be used in the where
        clause of the query.
        i just want s'thing simple like
        if exists ('test')
        then ---good
        else
        --create it
        end if;
        thanx in advance!!!

        When you have proper exception handling in your code, you don't NEED
        to check whether a table exists. Stop programming silly tests like
        this one, and LEARN pl/sql, start UNLEARNING your bad sqlserver habits
        NOW

        Oracle != Sqlserver.

        Sybrand Bakker
        Senior Oracle DBA

        Comment

        Working...