IF EXISTS

(12cR1)

--テーブル

select * from user_tables where table_name ='TAB1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);
→「create table if not exists」は未対応

drop table tab1;
drop table if exists tab1;
→「drop table if exists」は未対応


--インデックス
select * from user_indexes where index_name ='IND1';


create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1;
drop index if exists ind1;
→「drop index if exists」は未対応

 

(23c)
https://oracle-base.com/articles/23c/if-not-exists-ddl-clause-23c

 

--テーブル

select * from user_tables where table_name ='TAB1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);

drop table tab1;
drop table if exists tab1;

 

--インデックス
select * from user_indexes where index_name ='IND1';


create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);

drop index ind1;
drop index if exists ind1;

 

(5.6)
--テーブル

show tables like 'tab1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);

drop table tab1;
drop table if exists tab1;


--インデックス
show index in tab1;

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1 on tab1;
drop index if exists ind1 on tab1;
→「drop index if exists」は未対応

(8)
--テーブル

show tables like 'tab1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);

drop table tab1;
drop table if exists tab1;


--インデックス
show index in tab1;

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1 on tab1;
drop index if exists ind1 on tab1;
→「drop index if exists」は未対応

 

(9.4)
--テーブル

\dt tab1;

create table tab1(col1 int);
create table if not exists tab1(col1 int);

drop table tab1;
drop table if exists tab1;

--インデックス
\di ind1;

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1;
drop index if exists ind1;


(10)
--テーブル

\dt tab1;

create table tab1(col1 int);
create table if not exists tab1(col1 int);

drop table tab1;
drop table if exists tab1;


--インデックス
\di ind1;

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);

drop index ind1;
drop index if exists ind1;

 

(2014)
--テーブル
select * from sys.tables where name ='tab1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);
→「create table if not exists」は未対応

drop table tab1;
drop table if exists tab1;
→「drop table if exists」は未対応

 


--インデックス
select * from sys.indexes where name = 'ind1';

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1 on tab1;
drop index if exists ind1 on tab1;
→「drop index if exists」は未対応


(2016)
--テーブル
select * from sys.tables where name ='tab1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);
→「create table if not exists」は未対応

drop table tab1;
drop table if exists tab1;

 


--インデックス
select * from sys.indexes where name = 'ind1';

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

drop index ind1 on tab1;
drop index if exists ind1 on tab1;

 

(2019)
--テーブル
select * from sys.tables where name ='tab1';

create table tab1(col1 int);
create table if not exists tab1(col1 int);
→「create table if not exists」は未対応

drop table tab1;
drop table if exists tab1;

 

--インデックス
select * from sys.indexes where name = 'ind1';

create index ind1 on tab1(col1);
create index if not exists ind1 on tab1(col1);
→「create index if not exists」は未対応

下記構文はインデックスがない場合に実行するとエラーとなる
create index ind1 on tab1(col1) WITH ( DROP_EXISTING = ON );

下記構文はインデックスがある場合に実行するとエラーとなる
create index ind1 on tab1(col1) WITH ( DROP_EXISTING = OFF );


drop index ind1 on tab1;
drop index if exists ind1 on tab1;