日期:2014-05-16 浏览次数:20572 次
with test_cc as (
  select 'A' root,'B' parent_root from dual union
  select 'B','C' from dual union
  select 'C','D' from dual union
  select 'C','E' from dual union
  select 'E','F' from dual
)
select level lv,
       connect_by_root(root) conn_root,
       connect_by_root(parent_root) conn_parent_root,
       --最后一个是A的才是leaf
       connect_by_isleaf,
       sys_connect_by_path(parent_root,'>')||'>'||root path
from test_cc
connect by prior root=parent_root;

with test_cc as (
  select 'A' root,'B' parent_root from dual union
  select 'B','C' from dual union
  select 'C','D' from dual union
  select 'C','E' from dual union
  select 'E','F' from dual
)
select level lv,
       connect_by_isleaf,
       connect_by_root(root)||sys_connect_by_path(parent_root,'>') path
from test_cc
connect by prior parent_root=root;


select level lv,
       connect_by_isleaf lf, 
       part_no,component_part,per_assembly,
       connect_by_root(part_no) rt_part_no,
       connect_by_root(component_part) rt_component_part,
       sys_connect_by_path(per_assembly,'>') path_value,
       connect_by_root(part_no)||sys_connect_by_path(component_part,'>') path_correct,
       substr(sys_connect_by_path(per_assembly,'*'),2,100) path_exp_value
from CY_BOM_COMPONENT --(select * from CY_BOM_COMPONENT where part_no='ABDEF')
connect by nocycle prior component_part = part_no 
order by path_correct;

select * from(
    select level lv,
           connect_by_isleaf lf, 
           part_no,component_part,per_assembly,
           connect_by_root(part_no) rt_part_no,
           connect_by_root(component_part) rt_component_part,
           sys_connect_by_path(per_assembly,'>') path_value,
           connect_by_root(part_no)||sys_connect_by_path(component_part,'>') path_correct,
           substr(sys_connect_by_path(per_assembly,'*'),2,100) path_exp_value
    from CY_BOM_COMPONENT --(select * from CY_BOM_COMPONENT where part_no='ABDEF')
    connect by nocycle prior component_part = part_no 
)where lf=1
order by path_correct;