oracle9i - Multiple "execute immediately" queries in Oracle -


i have sequence of queries:

begin execute immediate 'drop table mytable1'; exception when others null; end;  begin execute immediate 'drop table mytable2'; exception when others null; end;  begin execute immediate 'drop table mytable3'; exception when others null; end; 

but when try execute in sql scratchpad says "encountered symbol begin" pointed me queries must in 1 begin... if remove begin end exept first begin , last end gives me "invalid sql statement" how perform multiple drop table or multiple create table upper pattern , check if tables exist? know style exception when others null; considered bad practice similar empty catch()'es in other languages thats easiest way me check if table exists/not exists in oracle

begin   execute immediate 'drop table mytable1';    execute immediate 'drop table mytable2';    execute immediate 'drop table mytable3'; exception   when others     null; end; 

works fine.


if ask me, exception when others null - should be avoided. if want check if table exists - query user_tables

declare   v_exists number;  begin  select 1 v_exists user_tables table_name = 'test';  if v_exists = 1   execute immediate 'drop table test'; end if;  exception   when no_data_found     dbms_output.put_line('table not found'); end; 

regd: comment, if still want go using method in question, wrap in outside anonymous block

begin    begin     execute immediate 'drop table mytable1';   exception     when others       null;   end;    begin     execute immediate 'drop table mytable2';   exception     when others       null;   end;    begin     execute immediate 'drop table mytable3';   exception     when others       null;   end;  end; 

result:

sql> begin   2     3    begin   4      execute immediate 'drop table mytable1';   5    exception   6      when others   7        null;   8    end;   9    10    begin  11      execute immediate 'drop table mytable2';  12    exception  13      when others  14        null;  15    end;  16    17    begin  18      execute immediate 'drop table mytable3';  19    exception  20      when others  21        null;  22    end;  23    24  end;  25    26  /  pl/sql procedure completed.  sql>  

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -