Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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
Sql 需要Oracle查询从具有1对多关系的表中检索信息_Sql_Database_Oracle - Fatal编程技术网

Sql 需要Oracle查询从具有1对多关系的表中检索信息

Sql 需要Oracle查询从具有1对多关系的表中检索信息,sql,database,oracle,Sql,Database,Oracle,我的表格中包含类似于以下内容的信息: 表A是电路列表: Circuit | CktType | CktSize -------------------------------- CKT1 | ABC123 | 10 CKT2 | ABC123 | 12 CKT3 | XYZ789 | 10 表B为电缆管道列表: Raceway | RwyType | RwySize --------------------------------

我的表格中包含类似于以下内容的信息:

表A是电路列表:

Circuit  |  CktType  |  CktSize
--------------------------------
CKT1     |  ABC123   |  10
CKT2     |  ABC123   |  12
CKT3     |  XYZ789   |  10
表B为电缆管道列表:

Raceway  |  RwyType  |  RwySize
--------------------------------
RWY1     |  C        |  4
RWY2     |  T        |  4x6
RWY3     |  T        |  8x12
表C是电路如何通过电缆管道的列表:

Circuit  |  Sequence |  Raceway
--------------------------------
CKT1     |  1        |  RWY1
CKT1     |  2        |  RWY2
CKT1     |  3        |  RWY3
CKT2     |  1        |  RWY2
表C可能有表A和表B中所有项目的条目,也可能没有。表C中没有表A和表B中每个项目的设置编号或最大条目数

我想在Oracle中编写两个查询来检索以下数据(很明显,这些查询非常相似,因此只需要在编写其中一个查询时寻求帮助)

所有电路信息以及电路通过的电缆管道 期望的结果:

Circuit  |  CktType  |  CktSize   |  Raceway
----------------------------------------------
CKT1     |  ABC123   |  10        | RWY1, RWY2, RWY3
CKT2     |  ABC123   |  12        | RWY2
CKT3     |  XYZ789   |  10        | (null)
Raceway  |  RwyType  |  RwySize  |  Circuit
----------------------------------------------
RWY1     |  C        |  4        | CKT1
RWY2     |  T        |  4x6      | CKT1, CKT2
RWY3     |  T        |  8x12     | CKT1
电缆管道中电路的所有电缆管道信息: 期望的结果:

Circuit  |  CktType  |  CktSize   |  Raceway
----------------------------------------------
CKT1     |  ABC123   |  10        | RWY1, RWY2, RWY3
CKT2     |  ABC123   |  12        | RWY2
CKT3     |  XYZ789   |  10        | (null)
Raceway  |  RwyType  |  RwySize  |  Circuit
----------------------------------------------
RWY1     |  C        |  4        | CKT1
RWY2     |  T        |  4x6      | CKT1, CKT2
RWY3     |  T        |  8x12     | CKT1

提前感谢。

编辑:重新阅读您的帖子后,我意识到这对您不起作用。请尝试“For XML路径”。
下面是一个很好的例子:

这将是两个查询之一。它产生每个电路信息,并根据这些信息生成由逗号分隔的电缆管道序列。。看看吧

  SELECT Circuit,
         CktType,
         CktSize,
         RTRIM (
            XMLAGG (XMLELEMENT (e, Raceway || ', ') ORDER BY Sequence).EXTRACT (
               '//text()'),
            ', ')
            Raceways
    FROM (SELECT t_A.Circuit,
                 t_A.CktType,
                 t_A.CktSize,
                 t_C.Raceway,
                 t_c.Sequence
            FROM    tableA t_A
                 LEFT OUTER JOIN
                    tableC t_C
                 ON t_A.Circuit = t_C.Circuit)
GROUP BY Circuit;