2

我正在创建可以教授 1 个或多个模块的人员对象。我有一个嵌套表,其中包含对模块表的引用。我还打算创建另一个来显示工作人员协调的模块。有没有办法将两个不同的嵌套表一起命名。我尝试过:

CREATE TYPE staff_typ UNDER person_typ(
staffID VARCHAR2(10),
universityEmail VARCHAR2(30),
office_ref REF office_typ,
coordintor_typ moduleProfile_typ,
teaches moduleProfile_typ)
NOT FINAL
/
CREATE TABLE staff_tab OF staff_typ;
NESTED TABLE teaches STORE AS lectures,
NESTED TABLE coordinator_typ STORE AS coordinates;

但我得到一个包含未知语句错误的脚本。谁能举例说明如何在这种情况下显示两个不同的嵌套表?

4

1 回答 1

1

谁能举例说明如何在这种情况下显示两个不同的嵌套表?

CREATE TYPE varchar_ot AS OBJECT (varchar_field VARCHAR2(40));
CREATE TYPE number_ot  AS OBJECT (number_field  NUMBER);

CREATE TYPE varchar_ntt AS TABLE OF varchar_ot;
CREATE TYPE number_ntt  AS TABLE OF number_ot;

CREATE TABLE collections
(
    col_id      NUMBER
,   col_varchar varchar_ntt
,   col_number  number_ntt
)
NESTED TABLE col_varchar STORE AS col_varchar_nt
NESTED TABLE col_number  STORE AS col_number_nt
;
-- table COLLECTIONS created.

INSERT INTO collections VALUES
(
    1
,   (varchar_ntt(varchar_ot('a'), varchar_ot('b')))
,   (number_ntt (number_ot(11),   number_ot(22)))
);
-- 1 rows inserted.

INSERT INTO collections VALUES
(
    2
,   (varchar_ntt(varchar_ot('c'), varchar_ot('d')))
,   (number_ntt (number_ot(33),   number_ot(44)))
);
-- 1 rows inserted.

SELECT  col_id, varchar_field, number_field
FROM    collections, TABLE(collections.col_varchar), TABLE(collections.col_number)
ORDER   BY
        3, 2, 1
;

COL_ID  VARCHAR_FIELD   NUMBER_FIELD
1       a               11
1       b               11
1       a               22
1       b               22
2       c               33
2       d               33
2       c               44
2       d               44

声明一个对象类型的表,其中对象包含两个嵌套表

CREATE TYPE a_varchar_ntt AS TABLE OF VARCHAR2(30);
CREATE TYPE a_number_ntt  AS TABLE OF NUMBER;

CREATE TYPE var_num_ot AS OBJECT
(
    col_var a_varchar_ntt
,   col_num a_number_ntt
);

TYPE var_num_ntt AS TABLE OF var_num_ot;
/*
Error report:
Unknown Command
*/

如果这不是一个练习,那么您将走错方向,使事情变得过于复杂。

于 2013-06-11T20:24:50.177 回答