2016-01-27 101 views
0

我作業的一部分。我知道這很基本,但對我來說並不那麼直觀。 我創建這個:基本對象:ORA-00932當INSERT對象類型數據時

CREATE TYPE Address_typ AS OBJECT (
     AddressNo NUMBER, 
     Street VARCHAR2(64), 
     PostCode VARCHAR2(9), 
     Town  VARCHAR2(64) 
    ); 
    /

    CREATE TYPE Customer_typ AS OBJECT (
     CustNo   NUMBER, 
     customer_name VARCHAR2(64), 
     VAT_NO   VARCHAR2(18), 
     Address_ref REF Address_typ 
    ); 
    /

CREATE TABLE Address_table OF Address_typ; 

CREATE TABLE Customer_table OF Customer_typ 
(Address_ref SCOPE IS Address_table); 

此插入的工作原理:

INSERT INTO Address_table VALUES(Address_typ(1,'Strumykowa 5','65-001', 'Zielona Góra')); 

和一個下面是不是(空Address_table):

INSERT INTO Customer_table VALUES(Customer_Typ(1,'PPUH ZZPD', '12345678901', Address_typ(1,'Strumykowa 5','65-001', 'Zielona Góra'))); 

我應該如何正確插入到CUSTOMER_TABLE

+0

Customer_typ應該是相對的嗎?......我想沒有必要。 – mallorn

回答

2

這種方式將工作:

INSERT INTO Customer_table 
VALUES(Customer_Typ(1,'PPUH ZZPD', '12345678901', (select ref(a) from address_table a where a.AddressNo = 1))); 
+0

謝謝,奇怪的是我沒有弄清楚自己。 – mallorn