2013-06-20 41 views
0

我試圖創建一個超類型客戶服務和子類型代理和主管,因此它們可以固有的值,但是當我嘗試在oracle sql中運行此操作時:出現一條消息oracle11g sql:警告:使用編譯錯誤創建的類型

Warning: Type created with compilation errors.

有什麼不對下面的代碼?

Create or replace type customer_s_type as object (
    csID number, 
    csName varchar(15), 
    csType number) NOT FINAL; 

Create or replace type supervisor_type UNDER customer_s_type (title varchar (10)); 

Create or replace type agent_type UNDER customer_s_type (title varchar (10)); 

Create table supervisor of supervisor_type (
    CONSTRAINT supervisor_PK PRIMARY KEY (csID)); 

Create table agent of agent_type (CONSTRAINT agent_PK PRIMARY KEY (csID)); 

create table customer_service(
    csID number(10), 
    csType number(10), 
    constraint supervisor_pk primary key(csID)); 
+1

您的customer_service表具有重複的約束名稱,但除此之外似乎沒有任何錯誤。請參閱[SQLFiddle](http://sqlfiddle.com/#!4/f3996)。另外,請使用出色的格式工具代碼。它使讀者感興趣得多。 –

+0

什麼'顯示錯誤'給你? –

+0

錯誤是:警告:類型創建與編譯錯誤。正如你所建議的,需要爲約束supervisor_pk主鍵(csID)更改customer_service表);並且還需要/爲下面的用戶建議的單獨命令'Alex Poole' –

回答

2

可以在SQL * Plus或SQL Developer中,或select * from user_errors使用show errors,看到錯誤的詳細信息。

由於您已經顯示了六條命令,並且警告是關於前三條中的一條(因爲它指的是type),並且除了指向註釋中指定的約束之外它們看起來獨立,它看起來像整個腳本是被解釋爲一個命令。這取決於您的客戶端設置,但您可能只需要使用/來分隔命令以使其執行。 Becuase類型可以包含PL/SQL ;不作爲語句分隔符處理。因此:

Create or replace type customer_s_type as object (
    csID number, 
    csName varchar(15), 
    csType number) NOT FINAL; 
/

Create or replace type supervisor_type UNDER customer_s_type (title varchar (10)); 
/

Create or replace type agent_type UNDER customer_s_type (title varchar (10)); 
/

Create table supervisor of supervisor_type (
    CONSTRAINT supervisor_PK PRIMARY KEY (csID)); 

Create table agent of agent_type (CONSTRAINT agent_PK PRIMARY KEY (csID)); 

create table customer_service(
    csID number(10), 
    csType number(10), 
    constraint customer_service_pk primary key(csID)); 
+0

當您突出顯示'/'來分隔命令和lats行customer_service_pk主鍵時,我有兩個錯誤。非常感謝你。 –