Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: Check table existance

Re: Check table existance

From: Brian Peasland <peasland_at_edcmail.cr.usgs.gov>
Date: Fri, 19 Jan 2001 13:39:31 GMT
Message-ID: <3A684393.6A412F9D@edcmail.cr.usgs.gov>

You'll have to use PL/SQL to do what you want. A short sample might look like:

DECLARE
   table_exists NUMBER;
BEGIN
   SELECT count(*) INTO table_exists

      FROM user_tables WHERE table_name='TEST';    IF table_exists > 0 THEN

      EXECUTE IMMEDIATE drop table test;    END IF;
END; HTH,
Brian

Ryan Lubke wrote:
>
> Hello,
>
> I would like to be able to check for existence of a table,
> if it does exist, then I would like to drop that table.
>
> if ( <table_exits )
> drop table <tablename>
>
> So far, I have been unsuccessful in what I've tried.
>
> The following select could work:
>
> SELECT 1 from user_tables where EXISTS ( select TABLE_NAME from
> user_tables where TABLE_NAME = 'test' )
>
> This seems a bit "clunky" from the SQL dialect I'm used to.
>
> Additionally, if I put this select anywhere near an IF
> statement, I get complaints.
>
> I've search the internet for suggestions and have not found
> any so, I'm hoping you folks will have one.
>
> Thanks,
>
> Ryan Lubke
 

-- 
========================================
Brian Peasland
Raytheons Systems at
  USGS EROS Data Center
These opinions are my own and do not
necessarily reflect the opinions of my 
company!
========================================
Received on Fri Jan 19 2001 - 07:39:31 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US