0

我制作了两个对象表,参考 M:M,插入工作正常,但是当我尝试更新参考时,我得到了错误。

错误: SQL 错误:ORA-00904:“A”。“ATS_PN”:“%s:无效标识符”

CREATE OR REPLACE TYPE STUDENTI AS OBJECT(
    S_NUM   INT,
    S_UZV   VARCHAR2(30)
);

CREATE OR REPLACE TYPE PASNIEDZEJI AS OBJECT(
    P_NUM   INT,
    P_UZV   VARCHAR2(30)
);

CREATE OR REPLACE TYPE ATS_ST AS OBJECT(
    ID  INT,
    ST_ID REF STUDENTI
);

CREATE OR REPLACE TYPE ATS_PN AS OBJECT(
    ID  INT,
    PN_ID REF PASNIEDZEJI
);

CREATE OR REPLACE TYPE ATS_P AS TABLE OF ATS_PN;
CREATE OR REPLACE TYPE ATS_S AS TABLE OF ATS_ST;

CREATE OR REPLACE TYPE O_STUDENTI AS OBJECT(
    STUD STUDENTI,
    PASN ATS_P
);

CREATE OR REPLACE TYPE O_PASNIEDZEJI AS OBJECT(
    PASN PASNIEDZEJI,
    STUD ATS_S
);

CREATE TABLE T_STUDENTI OF O_STUDENTI
NESTED TABLE PASN STORE AS P_TBL;

CREATE TABLE T_PASNIEDZEJI OF O_PASNIEDZEJI
NESTED TABLE STUD STORE AS S_TBL;

INSERT INTO T_STUDENTI VALUES (STUDENTI(191, 'BRONES'), NULL);

INSERT INTO T_PASNIEDZEJI VALUES (PASNIEDZEJI(53, 'JHONES'), NULL);
INSERT INTO T_PASNIEDZEJI VALUES (PASNIEDZEJI(54, 'HIKKAEV'), NULL);

UPDATE T_STUDENTI A SET A.PASN = (1, 'TEST') WHERE A.STUD.S_NUM = 191; --misstake some where ther :/
4

1 回答 1

0

我没有在功能上关注你正在做的事情,但我已经从你的对象中删除了 REF,因为它很难在 SQL 中处理。

您会注意到t_studenti.pasnis ats_pwhich 是一个ats_pn包含 anid和 a的表pasniedzeji:您必须构建整个层次结构。

此代码将让您更新表:

CREATE OR REPLACE TYPE STUDENTI AS OBJECT(
    S_NUM   INT,
    S_UZV   VARCHAR2(30)
);

CREATE OR REPLACE TYPE PASNIEDZEJI AS OBJECT(
    P_NUM   INT,
    P_UZV   VARCHAR2(30)
);

CREATE OR REPLACE TYPE ATS_ST AS OBJECT(
    ID  INT,
    ST_ID STUDENTI
);

CREATE OR REPLACE TYPE ATS_PN AS OBJECT(
    ID  INT,
    PN_ID PASNIEDZEJI
);

CREATE OR REPLACE TYPE ATS_P AS TABLE OF ATS_PN;
CREATE OR REPLACE TYPE ATS_S AS TABLE OF ATS_ST;

CREATE OR REPLACE TYPE O_STUDENTI AS OBJECT(
    STUD STUDENTI,
    PASN ATS_P
);

CREATE OR REPLACE TYPE O_PASNIEDZEJI AS OBJECT(
    PASN PASNIEDZEJI,
    STUD ATS_S
);

CREATE TABLE T_STUDENTI OF O_STUDENTI
NESTED TABLE PASN STORE AS P_TBL;

CREATE TABLE T_PASNIEDZEJI OF O_PASNIEDZEJI
NESTED TABLE STUD STORE AS S_TBL;

INSERT INTO T_STUDENTI VALUES (STUDENTI(191, 'BRONES'), NULL);

INSERT INTO T_PASNIEDZEJI VALUES (PASNIEDZEJI(53, 'JHONES'), NULL);
INSERT INTO T_PASNIEDZEJI VALUES (PASNIEDZEJI(54, 'HIKKAEV'), NULL);

UPDATE t_studenti a
   SET a.pasn = ats_p(ats_pn(1, -- ??
                             pasniedzeji(1,
                                         'TEST')))
 WHERE a.stud.s_num = 191; 
于 2020-12-04T16:43:56.257 回答