IF [NOT] EXISTS DDL Clause in Oracle Database 23ai/26ai
Prevent errors during object creation and removal using the IF [NOT] EXISTS DDL clause in Oracle Database 23ai/26ai.
oracle 23configurationintermediate
by OracleDba
25 views
Prevent errors during object creation and removal using the IF [NOT] EXISTS DDL clause in Oracle Database 23ai/26ai.
123456789101112131415161718192021
-- Test user.
conn sys/SysPassword1@//localhost:1521/freepdb1 as sysdba
create user testuser1 identified by testuser1;
grant connect, resource to testuser1;
-- Test objects.
conn testuser1/testuser1@//localhost:1521/freepdb1
create table t1 (id number);
create sequence t1_seq;
create view t1_v as
select * from t1;
create procedure p1 as
begin
null;
end;
/123456789101112131415161718192021222324252627282930313233343536373839404142434445
SQL> conn sys/SysPassword1@//localhost:1521/freepdb1 as sysdba
Connected.
SQL> create user testuser1 identified by testuser1;
create user testuser1 identified by testuser1
*
ERROR at line 1:
ORA-01920: user name 'TESTUSER1' conflicts with another user or role name
SQL>
SQL> conn testuser1/testuser1@//localhost:1521/freepdb1
Connected.
SQL> create table t1 (id number);
create table t1 (id number)
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL>
SQL> create sequence t1_seq;
create sequence t1_seq
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
SQL>
SQL> drop table t3 purge;
drop table t3 purge
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
SQL> conn sys/SysPassword1@//localhost:1521/freepdb1 as sysdba
Connected.
SQL> create user if not exists testuser1 identified by testuser1;
User created.
SQL>
SQL> drop user if exists testuser3 cascade;
User dropped.
SQL>
SQL> conn testuser1/testuser1@//localhost:1521/freepdb1
Connected.
SQL> create table if not exists t1 (id number);
Table created.
SQL>
SQL> create sequence if not exists t1_seq;
Sequence created.
SQL>
SQL> create view if not exists t1_v as
select * from t1;
View created.
SQL>
SQL> create procedure if not exists p1 as
begin
null;
end;
/
Procedure created.
SQL>
SQL> drop table if exists t3;
Table dropped.
SQL> drop sequence if exists t3_seq;
Sequence dropped.
SQL> drop view if exists t3_v;
View dropped.
SQL> drop procedure if exists p3;
Procedure dropped.
SQL>
SQL> alter table if exists t1 add (id number);
alter table if exists t1 add (id number)
*
ERROR at line 1:
ORA-01430: column being added already exists in table
SQL>1234567891011121314151617181920212223
SQL> create or replace view if not exists t1_v as
select * from t1;
create or replace view if not exists t1_v as
*
ERROR at line 1:
ORA-11541: REPLACE and IF NOT EXISTS cannot coexist in the same DDL statement
SQL>
SQL> create or replace procedure if not exists p1 as
begin
null;
end;
/
create or replace procedure if not exists p1 as
*
ERROR at line 1:
ORA-11541: REPLACE and IF NOT EXISTS cannot coexist in the same DDL statement
SQL>Please to add comments
No comments yet. Be the first to comment!