SOLVED
ORA-02303: cannot drop or replace a type with type or table dependents
Asked by OracleDba••23 views•oracle
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
ORA-02303: cannot drop or replace a type with type or table dependents
ORA-02303: cannot drop or replace a type with type or table dependents
Cause:
. An attempt was made to drop or replace a type that has type or table dependents.
Action:
For DROP TYPE, drop all type(s) and table(s) depending on the type and then retry the operation, or use the FORCE option. For CREATE TYPE, drop all type(s) and table(s) depending on the type and then retry the operation, or drop all table(s) depending on the type and retry with the FORCE option
Little Background:
When we try to replace an existing user defined object type which is being referenced by other objects, the developer must take appropriate actions in order to successfully carry out the upgrade. The newer version of user defined object type, even with one simple change, can not replace existing one and leads to ORA-02303.
I faced ORA-02303 in our one of the development environment, when a user defined object type was getting replace with some changes and the existing type was being referenced in some of the objects.
Reproduce ORA-02303
Lets first try create a type and a table which is dependent on it. We will also insert some records as there always will be records in production environment
SQL> create or replace type
2 type_address as object(
3 address varchar2(2000),
4 city varchar2(100),
5 state varchar2(100),
6 country varchar2(100)
7 );
8 /
Type created.
SQL> create or replace type type_address_tab as table of type_address;
2 /
Type created.
SQL> create table employee (
2 empid number(10),
3 ename varchar2(100),
4 address type_address_tab
5 ) nested table address store as emp_address_tab;
Table created.
SQL> insert into employee values
2 (1,'Ankush',
3 type_address_tab(
4 type_address('253 SN','Gzb','UP','India'),
5 type_address('234 GP','Gzb','UP','India')
6 )
7 );
1 row created.
SQL> insert into employee values
2 (1,'Chetan',
3 type_address_tab(
4 type_address('123 IP','Gzb','UP','India'),
5 type_address('987 UN','Delhi','Delhi','India')
6 )
7 );
1 row created.
SQL> select e.empid, e.ename, a.address, a.city, a.state, a.country
2 from
3 employee e, table(e.address) a;
EMPID ENAME ADDRESS CITY STATE COUNTRY
----- ---------- ---------- ---------- ---------- ----------
1 Ankush 253 SN Gzb UP India
1 Ankush 234 GP Gzb UP India
1 Chetan 123 IP Gzb UP India
1 Chetan 987 UN Delhi Delhi India
Now we have all the setup. What if the requirement comes to just add a column for PIN in our type. A straight "create or replace type" command will lead us to oracle exception ORA-02303.
SQL> create or replace type
2 type_address as object(
3 address varchar2(2000),
4 city varchar2(100),
5 state varchar2(100),
6 country varchar2(100),
7 pin varchar2(10),
8 );
9 /
create or replace type
*
ERROR at line 1:
ORA-02303: cannot drop or replace a type with type or table dependents#oracle#error