ORA-02303替换表中使用的对象类型

时间:2015-07-02 11:26:45

标签: sql oracle

我正在尝试在Oracle中创建一个对象,但是我收到了错误

ORA-02303: cannot drop or replace a type with type or table dependents.

我创建了对象address_ot来指定街道或城市或州或邮编号码中的地址字段。

可以检索first_namelast_name等值,但lv_address无法检索。

create or replace type address_ot AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));

create table exp_info
( first_name varchar2(50),
last_name varchar2(50),
birthdate DATE,
 address address_ot 
);

drop table exp_Info


DECLARE

lv_address address_ot; 

BEGIN
lv_address:= address_ot('California','Atlantia','AK',223);

insert into exp_info
values('Kara','Thrace','01-JAN-1980',lv_address);

END;

检查记录:

SELECT  * from exp_info;

1 个答案:

答案 0 :(得分:0)

一旦您创建了引用对象类型的表,除非您先删除表(或至少删除其对象列),否则无法修改类型:

create or replace type address_ot AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2));
/

Type ADDRESS_OT compiled

create table exp_info
( first_name varchar2(50),
last_name varchar2(50),
birthdate DATE,
 address address_ot 
);

Table EXP_INFO created.

create or replace type address_ot AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));
/

Error starting at line : 12 in command -
create or replace type address_ot AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));
Error report -
ORA-02303: cannot drop or replace a type with type or table dependents

即使使用force也会出现此错误,http://developer.android.com/guide/topics/resources/localization.html适用于类型依赖项但不依赖于表依赖项:

create or replace type address_ot force AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));
/

create or replace type address_ot force AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));
Error report -
ORA-22866: cannot replace a type with table dependents

如果删除表,则可以重新创建类型,然后重新创建表:

drop table exp_Info;

Table EXP_INFO dropped.

create or replace type address_ot AS OBJECT
(street varchar2(100),city varchar2(50), state varchar(2),zip number(9));
/

Type ADDRESS_OT compiled

create table exp_info
( first_name varchar2(50),
last_name varchar2(50),
birthdate DATE,
 address address_ot 
);

Table EXP_INFO created.

然后您的块和查询似乎有效:

DECLARE

lv_address address_ot; 

BEGIN
lv_address:= address_ot('California','Atlantia','AK',223);

insert into exp_info
values('Kara','Thrace','01-JAN-1980',lv_address);

END;
/

PL/SQL procedure successfully completed.

SELECT *from exp_info;

FIRST_NAME
--------------------------------------------------
LAST_NAME
--------------------------------------------------
BIRTHDATE
---------
ADDRESS
--------------------------------------------------------------------------------
Kara                                               
Thrace                                             01-JAN-80 
SCHEMA.ADDRESS_OT(California,Atlantia,AK,223)