Oracle CONNECT BY查询。如何显示初始条件

时间:2014-10-15 05:42:45

标签: sql oracle

我想使用列出分层结构的查询:

 SELECT LEVEL, PART_NO, COMPONENT_PART, QTY_PER_ASSEMBLY
   FROM MANUF_STRUCTURE 
CONNECT 
     BY PRIOR COMPONENT_PART = PART_NO AND 
        PRIOR CONTRACT = CONTRACT AND 
        PRIOR BOM_TYPE_DB = BOM_TYPE_DB 
        START WITH PART_NO = '&PN' ORDER SIBLINGS BY LINE_ITEM_NO;

我想将初始条件(在此示例中为'& PN')放入列表的第一列。我怎么能这样做?

我的目标是使用乘法初始条件运行此查询,并列出相应的初始条件。

你有什么想法吗?

谢谢,

2 个答案:

答案 0 :(得分:0)

您可以使用运算符CONNECT_BY_ROOT

文档:http://docs.oracle.com/database/121/SQLRF/operators004.htm#SQLRF51162

文档中的示例:http://docs.oracle.com/database/121/SQLRF/queries003.htm#i2069380

所以你可以这样做:

SELECT CONNECT_BY_ROOT PART_NO as ROOT_PART_NO,
       LEVEL, PART_NO, COMPONENT_PART, QTY_PER_ASSEMBLY
  FROM MANUF_STRUCTURE 
CONNECT BY
   PRIOR COMPONENT_PART = PART_NO AND 
   PRIOR CONTRACT = CONTRACT AND 
   PRIOR BOM_TYPE_DB = BOM_TYPE_DB 
START WITH PART_NO IN ('&PN1', '&PN2', '&PN3')
ORDER SIBLINGS BY LINE_ITEM_NO;

答案 1 :(得分:0)

试试这个

SELECT '&PN' initial_condition, LEVEL, PART_NO, COMPONENT_PART, QTY_PER_ASSEMBLY
   FROM MANUF_STRUCTURE 
 CONNECT 
     BY PRIOR COMPONENT_PART = PART_NO AND 
        PRIOR CONTRACT = CONTRACT AND 
        PRIOR BOM_TYPE_DB = BOM_TYPE_DB 
        START WITH PART_NO = '&PN' ORDER SIBLINGS BY LINE_ITEM_NO;