声明一个对象类型的表,其中对象包含两个嵌套表
Posted
技术标签:
【中文标题】声明一个对象类型的表,其中对象包含两个嵌套表【英文标题】:Declaring a table of type object where the object contains two nested tables 【发布时间】:2013-04-23 23:23:46 【问题描述】:我正在创建可以教授 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;
但我得到一个包含未知语句错误的脚本。谁能举例说明如何在这种情况下显示两个不同的嵌套表?
【问题讨论】:
“of staff_typ”后面的正斜杠和分号有两处看起来很奇怪 谢谢斜线应该被删除。有没有办法声明两个不同的嵌套表,或者每个对象中只能有一个? 【参考方案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
*/
如果这不是一个练习,那么你就会走错方向,让事情变得过于复杂。
【讨论】:
以上是关于声明一个对象类型的表,其中对象包含两个嵌套表的主要内容,如果未能解决你的问题,请参考以下文章