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

Home -> Community -> Usenet -> c.d.o.server -> Re: Any way to "conditionally" drop a table?

Re: Any way to "conditionally" drop a table?

From: VC <boston103_at_hotmail.com>
Date: Tue, 28 Oct 2003 01:11:06 GMT
Message-ID: <Kmjnb.45255$e01.108392@attbi_s02>


Hello David,

Assuming you want to use Java for this sort of things, you can enclose the drop statement in the 'try ... catch' block:

Statement stmt = con.createStatement();
 try {
   stmt.executeUpdate("DROP TABLE " + table);  } catch (SQLException ex) {/* do a remedial action or just log an error message */ }

The same can be done in a sqlplus scrip::

begin
  execute immediate 'drop table t1';
exception

   when others then
     dbms_output.put_line('Table already exists'); end;

Rgds.

"David M. Karr" <david.karr_at_wamu.net> wrote in message news:cafe491.0310271439.45ac1079_at_posting.google.com...
> This is probably a FAQ, but I haven't been able to find any good
> information about this. Perhaps that means the answer is that I can't
> do it, but I'll give it a try anyway.
>
> In writing db setup scripts, it's convenient to add a "drop table"
> statement before "create table" statements. This works fine if the
> table already existed. If the table didn't exist, the script fails.
>
> Is it practical/feasible to write Oracle-specific SQL that I can pass
> through JDBC that will only drop the table if it exists, and ignore it
> if it doesn't exist? I remember a colleague at another job doing this
> quite a while ago, but I can't remember how it was done.
Received on Mon Oct 27 2003 - 19:11:06 CST

Original text of this message

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