database - Create or replace table in Oracle pl/sql -


i need script creates table or if exist drops it, , when recreates table. after research have found out create or replace table in pl/sql doesn't exist. come script :

declare    does_not_exist   exception;    pragma exception_init (does_not_exist, -942); begin    execute immediate 'drop table foobar'; exception    when does_not_exist          null; end; /   create table foobar (c1 int); 

is there proper way achieve functionality?

using global temporary table seem better option. however, if insist on dropping , re-adding tables @ runtime query 1 of _tables views (i.e. user_tables, dba_tables, all_tables) determine if table exists, drop if does, create it:

select count(*)   ncount   user_tables   table_name = 'foobar';  if ncount <> 0   execute immediate 'drop table foobar'; end if;  execute immediate 'create table foobar(...)'; 

share , enjoy.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -