2012-11-22 40 views
0

我有這樣的功課,我得程序添加到嵌套表,這裏的甲骨文 - 添加方法(程序)以嵌套表

create type associe_t as Object(noAs int, nomAs varchar(50), capAs int) 
/
create type lesAssocies_t as TABLE OF associe_t 
/
create type promoteur_t as Object(matP int, nomP varchar(50), adrP varchar(50), lesAssocies lesAssocies_t) 
/
create table promoteur of promoteur_t (
    constraint pk_promoteur primary key(matP)); 

create table promoteur of promoteur_t (
    constraint pk_promoteur primary key(matP), 
    constraint limCapAs check (capAs <= 1 000 000) 
) tableSpace TBS3202A2012 
NESTED TABLE lesAssocies STORE AS Table_lesAssocies ; 

我想在類型associe_t方法的結構,即可以根據參數中傳遞的數字更新記錄中的值。

於是,我就方法簽名添加到我喜歡的類型:

alter type associe_t add member procedure augmenteCapAs(P IN number) cascade ; 

我試過之後添加過程的主體:

CREATE or replace TYPE BODY associe_t AS 
MEMBER procedure augmenteCapAs(P in number) AS 
    BEGIN 
    update Table_lesAssocies t set t.capAs = P/100 where t.noAs = self.noAs; 
    END; 
END; 
/

如果我用表名Table_lesAssocies這會給我以下錯誤:

ORA-22812: cannot reference nested table column's storage table 

如果我使用表名稱lesAssocies_t它告訴我該表不存在。

我在做什麼錯?我很確定我不應該去與該表的物理名稱(Table_lesAssocies

我應該使用什麼表名稱?

回答

1

正如錯誤消息所述,您無法直接訪問(檢索或存儲)嵌套表的列 - 只能通過外部表訪問(檢索或存儲)嵌套表。所以你可能會重寫你的代碼如下:

SQL> create type associe_t as Object(noAs int, nomAs varchar(50), capAs int) 
    2/

Type created 


SQL> create type lesAssocies_t as TABLE OF associe_t 
    2/

Type created 


SQL> create type promoteur_t as Object(matP int, nomP varchar(50), adrP varchar(50), lesAssocies lesAssocies_t) 
    2/

Type created 


SQL> create table tb_promoteur of promoteur_t (
    2  constraint pk_promoteur primary key(matP) 
    3 )tablespace users 
    4 NESTED TABLE lesAssocies STORE AS Table_lesAssocies; 

Table created 

SQL> alter table table_lesassocies add constraint chk_capas check (capas < 1000000); 

Table altered 

SQL> alter type associe_t add member procedure augmenteCapAs(P IN number) cascade ; 

Type altered 


SQL> CREATE OR REPLACE TYPE BODY associe_t AS 
    2 MEMBER procedure augmenteCapAs(P in number) AS 
    3 BEGIN 
    4  update table(select lesAssocies 
    5      from tb_promoteur) t 
    6   set t.capAs = P/100 
    7  where t.noAs = self.noAs; 
    8 END; 
    9 END; 
10/

Type body created 
+0

謝謝!這就是我正在尋找的(語法Table(..)) – Pacane