Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Drop table
A copy of this was sent to petr_kucera_at_my-deja.com
(if that email address didn't require changing)
On Mon, 21 Feb 2000 10:10:46 GMT, you wrote:
>Is there a way how to drop a table in Oracle DB, but I'd like to check
>if this table alredy exists in database?
>Something like this:
>
>if exists(select * from user_tables where table_name='mytable') then
> drop table mytable;
>end if;
>
>but I can't use DDL statements.
>
>ThanX.
>
>
In Oracle8.0 and before you could create procedure like:
create or replace procedure execute_immediate( p_sql in varchar2 ) is
cursor_name pls_integer default dbms_sql.open_cursor; ignore pls_integer;
and then you can:
begin
for x in ( select * from dual
where exists ( select * from user_tables where table_name = 'MYTABLE' ) ) loop execute_immediate( 'drop table mytable' );end loop;
(see http://osi.oracle.com/~tkyte/Misc/RolesAndProcedures.html if you get insufficient priv error or object does not exist error)
In Oracle8i, release 8.1 and up you can just:
begin
for x in ( select * from dual
where exists ( select * from user_tables where table_name = 'MYTABLE' ) ) loop EXECUTE IMMEDIATE 'drop table mytable';end loop;
>
>
>
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
Thomas Kyte tkyte_at_us.oracle.com Oracle Service Industries Reston, VA USA
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Mon Feb 21 2000 - 07:52:24 CST