410

I'm writing some migration scripts for an Oracle database, and was hoping Oracle had something similar to MySQL's IF EXISTS construct.

Specifically, whenever I want to drop a table in MySQL, I do something like

DROP TABLE IF EXISTS `table_name`;

This way, if the table doesn't exist, the DROP doesn't produce an error, and the script can continue.

Does Oracle have a similar mechanism? I realize I could use the following query to check if a table exists or not

SELECT * FROM dba_tables where table_name = 'table_name';

but the syntax for tying that together with a DROP is escaping me.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
  • 1
    This feature is finally introduced in Oracle 23c - https://renenyffenegger.ch/notes/development/databases/Oracle/Releases-and-versions/23c/index – Dr Y Wit Mar 08 '23 at 23:21

16 Answers16

707

The best and most efficient way is to catch the "table not found" exception: this avoids the overhead of checking if the table exists twice; and doesn't suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller:

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE ' || table_name;
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
      END IF;
END;

23c syntax Since version 23c, Oracle supports a simpler IF EXISTS syntax for all drop DDL:

BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE IF EXISTS ' || table_name;
END;

ADDENDUM For reference, here are the equivalent blocks for other object types:

Sequence

BEGIN
  EXECUTE IMMEDIATE 'DROP SEQUENCE ' || sequence_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -2289 THEN
      RAISE;
    END IF;
END;

View

BEGIN
  EXECUTE IMMEDIATE 'DROP VIEW ' || view_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -942 THEN
      RAISE;
    END IF;
END;

Trigger

BEGIN
  EXECUTE IMMEDIATE 'DROP TRIGGER ' || trigger_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4080 THEN
      RAISE;
    END IF;
END;

Index

BEGIN
  EXECUTE IMMEDIATE 'DROP INDEX ' || index_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -1418 THEN
      RAISE;
    END IF;
END;

Column

BEGIN
  EXECUTE IMMEDIATE 'ALTER TABLE ' || table_name
                || ' DROP COLUMN ' || column_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -904 AND SQLCODE != -942 THEN
      RAISE;
    END IF;
END;

Database Link

BEGIN
  EXECUTE IMMEDIATE 'DROP DATABASE LINK ' || dblink_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -2024 THEN
      RAISE;
    END IF;
END;

Materialized View

BEGIN
  EXECUTE IMMEDIATE 'DROP MATERIALIZED VIEW ' || mview_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -12003 THEN
      RAISE;
    END IF;
END;

Type

BEGIN
  EXECUTE IMMEDIATE 'DROP TYPE ' || type_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;

Constraint

BEGIN
  EXECUTE IMMEDIATE 'ALTER TABLE ' || table_name
            || ' DROP CONSTRAINT ' || constraint_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -2443 AND SQLCODE != -942 THEN
      RAISE;
    END IF;
END;

Scheduler Job

BEGIN
  DBMS_SCHEDULER.drop_job(job_name);
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -27475 THEN
      RAISE;
    END IF;
END;

User / Schema

BEGIN
  EXECUTE IMMEDIATE 'DROP USER ' || user_name;
  /* you may or may not want to add CASCADE */
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -1918 THEN
      RAISE;
    END IF;
END;

Package

BEGIN
  EXECUTE IMMEDIATE 'DROP PACKAGE ' || package_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;

Procedure

BEGIN
  EXECUTE IMMEDIATE 'DROP PROCEDURE ' || procedure_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;

Function

BEGIN
  EXECUTE IMMEDIATE 'DROP FUNCTION ' || function_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -4043 THEN
      RAISE;
    END IF;
END;

Tablespace

BEGIN
  EXECUTE IMMEDIATE 'DROP TABLESPACE ' || tablespace_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -959 THEN
      RAISE;
    END IF;
END;

Synonym

BEGIN
  EXECUTE IMMEDIATE 'DROP SYNONYM ' || synonym_name;
EXCEPTION
  WHEN OTHERS THEN
    IF SQLCODE != -1434 THEN
      RAISE;
    END IF;
END;
Jon Heller
  • 34,999
  • 6
  • 74
  • 132
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158
  • 14
    And for dropping a USER, the SQLCODE to ignore is -1918. – Andrew Swan Jan 18 '11 at 04:22
  • 20
    One needs to write a procedure do do that? Isn't there a better way to do that? – Wilson Freitas Apr 25 '12 at 19:02
  • 3
    @WilsonFreitas - No, you don't need to write a procedure. You can use an anonymous block, as in the example here. – Jeffrey Kemp Apr 27 '12 at 03:28
  • 9
    If I add many `EXECUTE IMMEDIATE 'DROP TABLE mytable';` sentences (one for each table in the script), do I have to put one exception handler for each one, or is it enough to wrap all the senteces in one `BEGIN ... EXCEPTION ... END;` block? – Throoze Dec 17 '13 at 22:22
  • 3
    @Throoze, you need a separate exception handler for each one, otherwise the first exception will cause subsequent drops to be skipped. – Jeffrey Kemp Dec 18 '13 at 00:41
  • 3
    @JeffreyKemp For many `DROP` statements (like the 20 views I have to `DROP`), a procedure (perhaps created in a `DECLARE`) is probably more readable. To Wilson's point, you have to write a PL/SQL block instead of ordinary SQL, which seems like overkill. [PostgreSQL](http://www.postgresql.org/docs/9.3/static/sql-droptable.html) and [My SQL](http://dev.mysql.com/doc/refman/5.6/en/drop-table.html) have both added an `IF EXISTS` option to `DROP TABLE` (and a number of other kinds of `DROP`s) statements to simplify this use case. Interestingly, SQL Server hasn't implemented a feature like that. – jpmc26 Mar 18 '14 at 03:00
  • 2
    For completeness I've expanded this answer to cover most of the object types. – Jeffrey Kemp Jul 29 '14 at 05:53
  • 10
    @jpmc26: The equivalent for MS SQL is `IF OBJECT_ID('TblName') IS NOT NULL DROP TABLE TblName`. It seems the verbosity of a SQL language is proportional to the price. –  Aug 19 '14 at 16:37
  • 1
    @Jon, not really: you have to take into account the fact that in Oracle, you very rarely need to drop any object. If you're doing it right, you'll never drop anything :) – Jeffrey Kemp Aug 19 '14 at 22:39
  • 1
    add the / char after the begin end block if you have the create table straight after ... Error report: ORA-06550: row 15 ... col... PLS-00103: Encountered the symbol "CREATE" – Yordan Georgiev Nov 21 '14 at 10:48
  • 4
    @JeffreyKemp *What?* That is *very* untrue. It's perfectly sane to drop things that become obsolete as your application changes. For example, you might change a column's type because the old type no longer meets your requirements. You might even replace whole tables. Or in my case, I replaced an entire set of views because I completely rewrote the code that was using them. That's not to necessary say that you should drop objects *immediately* since that can make rollback harder, but once they've been out of use for a release or two, it's fine. – jpmc26 Dec 10 '14 at 23:53
  • @jpmc26, of course, it's relative - my "rarely" is in comparison with normal application code, which shouldn't normally drop a table. And if a table is not in use, I drop it straight away :) – Jeffrey Kemp Dec 11 '14 at 00:06
  • @jpmc26, but the *point* is that if you get the design right from the start, you never need to drop a table. Obviously, due to changing requirements, this is patently impossible; but you wouldn't expect a schema to evolve so drastically that having to type a few extra lines of code to do a drop table makes any significant difference to your development effort. – Jeffrey Kemp Dec 11 '14 at 00:08
  • 7
    @JeffreyKemp You wouldn't think so, but I've found time and time again that Oracle makes everything hard. When you spend an average of an hour per obscure syntax error or trying to figure out how to do something that's obvious and easy in another database (like conditionally drop an element) and those kinds of problems pop up daily, it adds up. Fast. – jpmc26 Dec 11 '14 at 00:42
  • I guess everyone's experience will be different, especially if you have to support multiple products. Personally I find reading the Oracle docs helpful for confirming the exact syntax required for any particular command. And StackOverflow, of course :) – Jeffrey Kemp Dec 11 '14 at 00:50
  • It may also be helpful to include a PURGE TABLE statement in the event that you really really really do not need to recover the table you are dropping. viz: <> BEGIN EXECUTE IMMEDIATE q'[DROP TABLE ]' || pTABLE; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END DropTab; <> BEGIN EXECUTE IMMEDIATE q'[PURGE TABLE ]' || pTABLE; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END PurgeTab; – Allen Nov 19 '15 at 13:31
  • @Allen nice idea, but I would never make it a default option - perhaps add it as an optional parameter to the procedure that must be explicitly set in order to do the purge. Note also that you can include the PURGE directive in the same command as the drop, you don't need a separate step. – Jeffrey Kemp Nov 19 '15 at 23:56
  • When did they introduce `CREATE OR REPLACE`? –  Dec 01 '17 at 16:19
  • 1
    you can create procedure and use it this way like mysql `CREATE OR REPLACE PROCEDURE drop_table(table_name IN VARCHAR2) IS BEGIN EXECUTE IMMEDIATE 'DROP TABLE ' || table_name; EXCEPTION WHEN OTHERS THEN IF SQLCODE != -942 THEN RAISE; END IF; END drop_table; / call drop_table('foo'); create table foo( "bar" NUMBER ) ` – kajibu Nov 29 '19 at 13:03
  • I am running on version 19 and the code above throws an error: ORA-06550: line 2, column 39: PLS-00201: identifier 'TPSREPORTING.IPC_PROJECT_SMALL' must be declared ORA-06550: line 2, column 4: PL/SQL: Statement ignored – ds_practicioner Jan 30 '20 at 05:00
  • @ds_practicioner your error indicates a problem with your code, not with the code quoted above. – Jeffrey Kemp Jan 30 '20 at 05:30
  • I am wondering why oracle doesn't come up with simple drop if exists. Does the MYSQL has any copyrights of the syntax? I don't think so. Or oracle is ashamed of implementing or feared of what people think if they copy? I always believe if there is some good feature somebody developed.. Nothing wrong in following the same. This feature looks trivial but I don't understand why they are not addressing it – Stunner Feb 28 '20 at 04:01
  • @Stunner there's no issues re copyright or "shame", it's just very very low on the list of priorities. – Jeffrey Kemp Feb 28 '20 at 08:58
  • that worked for me in the Explorer but not when I called it from cx_Oracle in Python. So I had to change it to a 'select count(table_name) from user_tables and if that showed existence I did a straight DROP. – CashCow Mar 03 '22 at 01:24
165
declare
   c int;
begin
   select count(*) into c from user_tables where table_name = upper('table_name');
   if c = 1 then
      execute immediate 'drop table table_name';
   end if;
end;

That's for checking whether a table in the current schema exists. For checking whether a given table already exists in a different schema, you'd have to use all_tables instead of user_tables and add the condition all_tables.owner = upper('schema_name')

Marius Burz
  • 4,555
  • 2
  • 18
  • 28
  • 48
    +1 This is better because do not relay on exception decoding to understand what to do. Code will be easier to mantain and understand – daitangio Nov 10 '11 at 14:08
  • 4
    Agree with @daitangio - performance generally doesn't trump maintainability with run-once deployment scripts. – pettys Mar 01 '13 at 16:32
  • 1
    I would be interested to understand if implicit-commit plays a part here. You would want the SELECT and DROP to be inside the same transaction. [ Obviously ignoring any subsequent DDL that may be executed. ] – Mathew Jul 31 '14 at 02:27
  • 2
    @Matthew, the DROP is a DDL command, so it will first issue a COMMIT, drop the table, then issue a 2nd COMMIT. Of course, in this example there is no transaction (since it's only issued a query) so it makes no difference; but if the user had previously issued some DML, it will be implicitly committed before any DDL is executed. – Jeffrey Kemp Jul 02 '15 at 02:26
30

I have been looking for the same but I ended up writing a procedure to help me out:

CREATE OR REPLACE PROCEDURE DelObject(ObjName varchar2,ObjType varchar2)
IS
 v_counter number := 0;   
begin    
  if ObjType = 'TABLE' then
    select count(*) into v_counter from user_tables where table_name = upper(ObjName);
    if v_counter > 0 then          
      execute immediate 'drop table ' || ObjName || ' cascade constraints';        
    end if;   
  end if;
  if ObjType = 'PROCEDURE' then
    select count(*) into v_counter from User_Objects where object_type = 'PROCEDURE' and OBJECT_NAME = upper(ObjName);
      if v_counter > 0 then          
        execute immediate 'DROP PROCEDURE ' || ObjName;        
      end if; 
  end if;
  if ObjType = 'FUNCTION' then
    select count(*) into v_counter from User_Objects where object_type = 'FUNCTION' and OBJECT_NAME = upper(ObjName);
      if v_counter > 0 then          
        execute immediate 'DROP FUNCTION ' || ObjName;        
      end if; 
  end if;
  if ObjType = 'TRIGGER' then
    select count(*) into v_counter from User_Triggers where TRIGGER_NAME = upper(ObjName);
      if v_counter > 0 then          
        execute immediate 'DROP TRIGGER ' || ObjName;
      end if; 
  end if;
  if ObjType = 'VIEW' then
    select count(*) into v_counter from User_Views where VIEW_NAME = upper(ObjName);
      if v_counter > 0 then          
        execute immediate 'DROP VIEW ' || ObjName;        
      end if; 
  end if;
  if ObjType = 'SEQUENCE' then
    select count(*) into v_counter from user_sequences where sequence_name = upper(ObjName);
      if v_counter > 0 then          
        execute immediate 'DROP SEQUENCE ' || ObjName;        
      end if; 
  end if;
end;

Hope this helps

Willem Renzema
  • 5,177
  • 1
  • 17
  • 24
Robert Vabo
  • 353
  • 4
  • 9
  • After I created above proc. delobject, I tried to call it issuing the following SQL. But it did not work. delobject('MyTable', 'TABLE'); I am getting the following error -------------------------------- Error starting at line 1 in command: delobject('MyTable', 'TABLE') Error report: Unknown Command – Shai Aug 09 '12 at 03:02
  • 1
    use the EXECUTE Command - EXECUTE DelObject ('MyTable','TABLE'); – Idan Yehuda Jul 07 '14 at 12:20
  • I like this more than the other solutions, and the fact you do a check on the object first to see it exists defends against SQL Injection. Also I want to check if an object exists after creating as part of unit testing. – CashCow Mar 01 '22 at 14:07
15

just wanted to post a full code that will create a table and drop it if it already exists using Jeffrey's code (kudos to him, not me!).

BEGIN
    BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE tablename';
    EXCEPTION
         WHEN OTHERS THEN
                IF SQLCODE != -942 THEN
                     RAISE;
                END IF;
    END;

    EXECUTE IMMEDIATE 'CREATE TABLE tablename AS SELECT * FROM sourcetable WHERE 1=0';

END;
mishkin
  • 5,932
  • 8
  • 45
  • 64
  • 3
    Personally, I'd put the CREATE TABLE in a separate step, since it doesn't need to be done dynamically and doesn't need an exception handler. – Jeffrey Kemp Dec 18 '13 at 04:34
13

With SQL*PLUS you can also use the WHENEVER SQLERROR command:

WHENEVER SQLERROR CONTINUE NONE
DROP TABLE TABLE_NAME;

WHENEVER SQLERROR EXIT SQL.SQLCODE
DROP TABLE TABLE_NAME;

With CONTINUE NONE an error is reported, but the script will continue. With EXIT SQL.SQLCODE the script will be terminated in the case of an error.

see also: WHENEVER SQLERROR Docs

trunkc
  • 6,223
  • 4
  • 34
  • 49
6

Another method is to define an exception and then only catch that exception letting all others propagate.

Declare
   eTableDoesNotExist Exception;
   PRAGMA EXCEPTION_INIT(eTableDoesNotExist, -942);
Begin
   EXECUTE IMMEDIATE ('DROP TABLE myschema.mytable');
Exception
   When eTableDoesNotExist Then
      DBMS_Output.Put_Line('Table already does not exist.');
End;
Leigh Riffel
  • 6,381
  • 3
  • 34
  • 47
  • 1
    @Sk8erPeter *"already does not exist"* vs. *"did exist, but no longer does"* :) – Jeffrey Kemp Oct 22 '15 at 00:37
  • I believe it's a best practice to `ALTER SESSION SET PLSQL_WARNINGS = 'ENABLE:ALL';` when running administrative scripts, and this solution avoids the compiler warning PLS-06009 you'll get from the accepted answer: "OTHERS handler does not end in RAISE or RAISE_APPLICATION_ERROR" – durette Aug 20 '22 at 05:03
5

I prefer following economic solution

BEGIN
    FOR i IN (SELECT NULL FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE' AND OBJECT_NAME = 'TABLE_NAME') LOOP
            EXECUTE IMMEDIATE 'DROP TABLE TABLE_NAME';
    END LOOP;
END;
Pavel S
  • 73
  • 1
  • 5
2

One way is to use DBMS_ASSERT.SQL_OBJECT_NAME :

This function verifies that the input parameter string is a qualified SQL identifier of an existing SQL object.

DECLARE
    V_OBJECT_NAME VARCHAR2(30);
BEGIN
   BEGIN
        V_OBJECT_NAME  := DBMS_ASSERT.SQL_OBJECT_NAME('tab1');
        EXECUTE IMMEDIATE 'DROP TABLE tab1';

        EXCEPTION WHEN OTHERS THEN NULL;
   END;
END;
/

DBFiddle Demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275
1

There is no 'DROP TABLE IF EXISTS' in oracle, you would have to do the select statement.

try this (i'm not up on oracle syntax, so if my variables are ify, please forgive me):

declare @count int
select @count=count(*) from all_tables where table_name='Table_name';
if @count>0
BEGIN
    DROP TABLE tableName;
END
Erich
  • 3,946
  • 1
  • 22
  • 21
  • I've made an attempt to translate the script to oracle syntax. – Tom Nov 25 '09 at 19:00
  • 3
    declare count number; begin select count(*) into count from all_tables where table_name = 'x'; if count > 0 then execute immediate 'drop table x'; end if; end; You cannot run DDL directly from a transaction block, you need to use execute. – Khb Nov 25 '09 at 19:04
  • Thanks very much! I hadn't realized the syntax was that different. I DID know you need to wrap the whole thing in a begin/end, but i figured it was being run in the middle of another script. Tom: I decided to leave my version and not copy yours, so I don't take any votes from you, who obviously has the right ansswer. – Erich Nov 25 '09 at 19:35
  • 1
    I do not think this will compile. It may also be important to include the schema owner here or you may get 'true' for a table you did not mean to get with the same name. – Allen Nov 19 '15 at 13:46
  • Your answer [was superseded](https://stackoverflow.com/a/1799215/1394393) by the correct Oracle syntax 10 minutes after this was posted. – jpmc26 Nov 29 '17 at 23:45
0

And if you want to make it re-enterable and minimize drop/create cycles, you could cache the DDL using dbms_metadata.get_ddl and re-create everything using a construct like this: declare v_ddl varchar2(4000); begin select dbms_metadata.get_ddl('TABLE','DEPT','SCOTT') into v_ddl from dual; [COMPARE CACHED DDL AND EXECUTE IF NO MATCH] exception when others then if sqlcode = -31603 then [GET AND EXECUTE CACHED DDL] else raise; end if; end; This is just a sample, there should be a loop inside with DDL type, name and owner being variables.

0

A block like this could be useful to you.

DECLARE
    table_exist INT;

BEGIN
    SELECT Count(*)
    INTO   table_exist
    FROM   dba_tables
    WHERE  owner = 'SCHEMA_NAME' 
    AND table_name = 'EMPLOYEE_TABLE';

    IF table_exist = 1 THEN
      EXECUTE IMMEDIATE 'drop table EMPLOYEE_TABLE';
    END IF;
END;  
0

The following snippet worked for me

BEGIN
       EXECUTE IMMEDIATE 'DROP TABLE schema_name.table_name';
    EXCEPTION
       WHEN OTHERS THEN
          IF SQLCODE != -942 THEN
             RAISE;
          END IF;
    END;
PKS
  • 618
  • 1
  • 7
  • 19
-1

You could always catch the error yourself.

begin
execute immediate 'drop table mytable';
exception when others then null;
end;

It is considered bad practice to overuse this, similar to empty catch()'es in other languages.

Regards
K

Khb
  • 1,423
  • 9
  • 9
-2

I prefer to specify the table and the schema owner.

Watch out for case sensitivity as well. (see "upper" clause below).

I threw a couple of different objects in to show that is can be used in places besides TABLEs.

.............

declare
   v_counter int;
begin
 select count(*) into v_counter from dba_users where upper(username)=upper('UserSchema01');
   if v_counter > 0 then
      execute immediate 'DROP USER UserSchema01 CASCADE';
   end if; 
end;
/



CREATE USER UserSchema01 IDENTIFIED BY pa$$word
  DEFAULT TABLESPACE users
  TEMPORARY TABLESPACE temp
  QUOTA UNLIMITED ON users;

grant create session to UserSchema01;  

And a TABLE example:

declare
   v_counter int;
begin
 select count(*) into v_counter from all_tables where upper(TABLE_NAME)=upper('ORDERS') and upper(OWNER)=upper('UserSchema01');
   if v_counter > 0 then
      execute immediate 'DROP TABLE UserSchema01.ORDERS';
   end if; 
end;
/   
granadaCoder
  • 26,328
  • 10
  • 113
  • 146
-2

Sadly no, there is no such thing as drop if exists, or CREATE IF NOT EXIST

You could write a plsql script to include the logic there.

http://download.oracle.com/docs/cd/B12037_01/server.101/b10759/statements_9003.htm

I'm not much into Oracle Syntax, but i think @Erich's script would be something like this.

declare 
cant integer
begin
select into cant count(*) from dba_tables where table_name='Table_name';
if count>0 then
BEGIN
    DROP TABLE tableName;
END IF;
END;
Tom
  • 43,810
  • 29
  • 138
  • 169
  • declare cant integer; tablename varchar2(100) := 'BLABLABL'; begin select count(*) into cant from dba_tables where lower(table_name) = tablename; if cant > 0 then execute immediate 'DROP TABLE tablename'; END IF; end; – Oğuz Nov 18 '20 at 13:55
-2
BEGIN
   EXECUTE IMMEDIATE 'DROP TABLE "IMS"."MAX" ';
EXCEPTION
   WHEN OTHERS THEN
      IF SQLCODE != -942 THEN
         RAISE;
          END IF;
         EXECUTE IMMEDIATE ' 
  CREATE TABLE "IMS"."MAX" 
   (    "ID" NUMBER NOT NULL ENABLE, 
    "NAME" VARCHAR2(20 BYTE), 
     CONSTRAINT "MAX_PK" PRIMARY KEY ("ID")
  USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSAUX"  ENABLE
   ) SEGMENT CREATION IMMEDIATE 
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "SYSAUX"  ';


END;

// Doing this code, checks if the table exists and later it creates the table max. this simply works in single compilation

Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126