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

Home -> Community -> Usenet -> c.d.o.misc -> Re: sql script delete all tables

Re: sql script delete all tables

From: Tony <andrewst_at_onetel.net.uk>
Date: 22 Mar 2003 07:26:48 -0800
Message-ID: <c0e3f26e.0303220726.3de05eff@posting.google.com>


Tim X <timx_at_spamto.devnul.com> wrote in message news:<87of43lptd.fsf_at_tiger.rapttech.com.au>...
> Untested and off the top of my head - but it might give you the
> idea. ASsuming oracle 8i or better
>
> set serveroutput on size 1000000
> declare
> cursor tab_list is
> select table_name
> from user_tables;
> tname tab_list_at_ROWTYPE;
> sql_str varchar2(256);
> begin
> for tname in tab_list loop
> sql_str := 'drop table '||tname;
> execute immediate sql_str;
> end loop;
> exception
> when others then
> dbms_output.put_line(SQLERRM);
> end;
> /

That will almost work, but has 1 bug and some redundant variable declarations, redundant exception handler etc. This is enough:

begin
  for trec in (select table_name from user_tables) loop     execute immediate 'drop table '||trec.table_name;   end loop;
end;
/ Received on Sat Mar 22 2003 - 09:26:48 CST

Original text of this message

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