Skip to Main Content

SQL Developer

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How do I conditionally drop a table in Oracle 11g using SQL Developer?

ToolTimeTaborOct 22 2020

I am working on an 11G instance, so the IF EXISTS functionality is not available.
Here is what I would like to do, logically:

IF (SELECT COUNT(*) RECORDS FROM ALL_TABLES WHERE TABLE_NAME = 'CRAFT') > 0 THEN
 DROP TABLE 'CRAFT';
END IF;

For simplicity, I did not include the Owner to ensure uniqueness on the result. But, concept is simple. Use a select statement to count the number of records with this table name and if that number is greater than (0) that it executes the inner code.
When I run this code in SQL Developer, I get an error relating to the IF statement.
image.pngSo, what would the syntax look like to do this conditional drop?
Thanks.

This post has been answered by L. Fernigrini on Oct 23 2020
Jump to Answer
Comments
Post Details
Added on Oct 22 2020
4 comments
3,159 views