Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Oracle SQL中创建引用的嵌套表?_Oracle_Ref_Object Oriented Database_Nested Table - Fatal编程技术网

如何在Oracle SQL中创建引用的嵌套表?

如何在Oracle SQL中创建引用的嵌套表?,oracle,ref,object-oriented-database,nested-table,Oracle,Ref,Object Oriented Database,Nested Table,考虑以下问题: 有交易类型和服务类型。每个事务一次涵盖一个或多个服务。但是,两个不同的交易可能涉及相同的服务 现在,使用关系数据库设计很容易整合它。您将有一个用于事务事务id的表,然后是一些数据字段,一个用于服务服务id的表,一些数据字段,还有一个将事务id链接到服务id的第三个表。这样,服务数据就不会重复,如果您需要(比如)检索事务中涉及的所有服务,您只需执行两个联接事务联接第三个表联接服务 据我所知,ref只是存储它所指向的记录(对象)的id,并隐式地在deref()上进行连接。因此,比方说

考虑以下问题:

交易类型和服务类型。每个事务一次涵盖一个或多个服务。但是,两个不同的交易可能涉及相同的服务

现在,使用关系数据库设计很容易整合它。您将有一个用于事务
事务id的表,然后是一些数据字段
,一个用于服务
服务id的表,一些数据字段
,还有一个将事务id链接到服务id的第三个表。这样,服务数据就不会重复,如果您需要(比如)检索事务中涉及的所有服务,您只需执行两个联接
事务联接第三个表联接服务

据我所知,
ref
只是存储它所指向的记录(对象)的id,并隐式地在
deref()上进行连接。因此,比方说,如果任何事务必须只覆盖其中一个服务,我可以对服务对象使用
ref
,而不是服务id+显式连接

据我所知,
嵌套表
只是一个私有表,它将一个对象的id链接到另一个对象的id,并在声明嵌套表的类型的所有对象之间共享。如果我没有大错特错的话,这个概念还使用了引擎盖下的连接。因此,如果服务在所有事务中都是唯一的,原则上我可以在事务中使用
嵌套的服务表

但是,问题是,每个事务可能有多个服务,并且它们可能重复。因此,在我看来,面向对象的解决方案是事务内部的
嵌套ref表。然而,我无法在互联网上找到任何关于这个想法的语法的线索,以及是否有可能做到这一点

以下是我的目标Oracle SQL类伪代码(它不起作用):

创建类型服务\u类型作为对象(
身份证号码(5),
--其他一些数据--
成本数字(4),
名称varchar2(32),
说明2(32)
---------------------
);
/
创建服务类型的表服务表(id主键);
/
创建类型服务\引用\类型,因为引用服务\类型范围是服务\表;
/
创建类型Service\u Reference\u Table\u type作为Service\u Reference\u type的表;
/
创建类型事务\u类型作为对象(
身份证号码(5),
服务服务参考表类型,
--其他一些数据--
名称varchar2(32),
说明2(32)
---------------------
);
嵌套表服务存储为事务\服务\嵌套\引用\表;
/

作为旁注:我知道面向对象的DBMS是垃圾,我不打算在任何实际项目中使用它。这是一个大学作业(我想知道他们为什么教这些东西)。

我不认为你离得太远,但你不需要
服务\u参考\u类型
,你可以一步创建一个参考表格:

create type Service_Type as object(
    id           number(5),
    -- some other data --
    cost         number(4),
    name         varchar2(32),
    description  varchar2(32)
    ---------------------
);
/

create table Service_Table of Service_Type (id primary key);

create type Service_Reference_Table_Type as table of ref Service_Type;
/

create type Transaction_Type as object(
    id           number(5),
    services     Service_Reference_Table_Type,
    -- some other data --
    name         varchar2(32),
    description  varchar2(32)
    ---------------------
)
/

create table Transaction_Table of Transaction_Type
nested table services store as Transaction_Service_Nested_Reference_Table;
包括插入和查询数据

有没有一种方法可以让裁判们也参与进来

如@MTO中所示,链接到:

alter table Transaction_Service_Nested_Reference_Table
add scope for (column_value) is Service_Table;

我不认为您离得太远,但您不需要
服务\u参考\u类型
,您可以一步创建参考表格:

create type Service_Type as object(
    id           number(5),
    -- some other data --
    cost         number(4),
    name         varchar2(32),
    description  varchar2(32)
    ---------------------
);
/

create table Service_Table of Service_Type (id primary key);

create type Service_Reference_Table_Type as table of ref Service_Type;
/

create type Transaction_Type as object(
    id           number(5),
    services     Service_Reference_Table_Type,
    -- some other data --
    name         varchar2(32),
    description  varchar2(32)
    ---------------------
)
/

create table Transaction_Table of Transaction_Type
nested table services store as Transaction_Service_Nested_Reference_Table;
包括插入和查询数据

有没有一种方法可以让裁判们也参与进来

如@MTO中所示,链接到:

alter table Transaction_Service_Nested_Reference_Table
add scope for (column_value) is Service_Table;

谢谢,这确实有效。有没有一种方法可以同时作用于refs?@AntonCurmanschii将作用域应用于嵌套表。谢谢,这确实有效。有没有一种方法可以同时作用于refs?@AntonCurmanschii了解如何将作用域应用于嵌套表。