I have to use an SQL statement to drop a table, it will crash if the table doesn't exist. Is it possible to use IF
statement to drop the table
s.executeUpdate("DROP TABLE employee");
Oracle does not support a construct like drop table if exists my_table
, which is apparently legal syntax in MySQL (and possibly other RDBMSs).
In a .SQL
script, where you're running DDL
to DROP
and/or CREATE
various objects, the Oracle standard is to drop the object, and ignore the error in cases where the object does not exist. If you wish, you can write code to check if the object exists (see DBA_OBJECTS
view) to only drop if it exists.
from the s.executeUpdate
, I gather that you're doing this in Java? If it was me, I'd just do the drop and ignore any not exists error.