Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Check table existance
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