本帖最后由 luoyunying 于 2011-09-21 14:29:01 编辑

解决方案 »

  1.   

    select col2 ,substr(aa,1,instr(aa,',')-1)*substr(aa,instr(aa,',')+1)
    from
    (select  col2,
            substr(sys_connect_by_path(col3,','),2) aa
    from test1
    where CONNECT_BY_ISLEAF=1
    start with col1='a'
    connect by    col1=  prior col2)
      

  2.   

    不行的,表中的数据是N层的!
    想了办法'1'||sys_connect_by_path(col3,',')||',' into :string 后分解字符串进行乘积
      

  3.   


    with tbl as
    (
        select 'a' as col1, 'b1' as col2, 1 as col3 from dual
         union all
        select 'a' as col1, 'b2' as col2, 0.5 as col3 from dual
         union all
        select 'b1' as col1, 'c1' as col2, 0.7 as col3 from dual
         union all
        select 'b2' as col1, 'c2' as col2, 2 as col3 from dual
    )
    select col2, 
           dbms_aw.eval_number(1 || SYS_CONNECT_BY_PATH(trim(to_char(col3,'99999990.99')),'*'))  as inum
      from tbl t
     where connect_by_isleaf = 1
    connect by prior col2 = col1
    start with col1 = 'a';
    COL2       INUM
    ---- ----------
    c1          0.7
    c2            1
      

  4.   


    with temp_table as
    (
        select 'a' as col1, 'b1' as col2, 1 as col3 from dual
         union all
        select 'a' as col1, 'b2' as col2, 0.5 as col3 from dual
         union all
        select 'b1' as col1, 'c1' as col2, 0.7 as col3 from dual
         union all
        select 'b2' as col1, 'c2' as col2, 2 as col3 from dual
    )select t1.col2,(t1.col3*t2.col3)
    from temp_table t1,
         temp_table t2
    where t1.col1 = t2.col2--结果
    c1 0.7
    c2 1
      

  5.   


    with tbl as
    (
        select 'a' as col1, 'b1' as col2, 2 as col3 from dual
         union all
        select 'a' as col1, 'b2' as col2, 0.5 as col3 from dual
         union all
        select 'b1' as col1, 'c1' as col2, 0.7 as col3 from dual
         union all
        select 'b2' as col1, 'c2' as col2, 2 as col3 from dual
        union all
        select 'c1' as col1, 'd1' as col2, 0.8 as col3 from dual
    )
     select col2,
     dbms_aw.eval_number(1 || SYS_CONNECT_BY_PATH(trim(to_char(col3,'99999990.99')),'*'))  as inum
     from tbl 
    where connect_by_isleaf = 1
    start with col1 = 'a' connect by prior col2 = col1;
      

  6.   


    把我的脚本改一下 connect by 的位置就来蒙分?
      

  7.   

    SELECT COL2,COL3 FROM NODE_T T1 WHERE EXISTS (SELECT 1 FROM NODE_T T2 WHERE T1.COL1 = T2.COL2 ) 
     这样,如果是两级就可以,但子节点一多就不行了,可以往这个方向想想..