insert into B values
as select A.value as child,C.value as parent from A,(select A.value from A) C
where C.value like ('A.value%') and length(C.value)=Length(A.value)+1不知道对不对,你试试吧。我也试试。

解决方案 »

  1.   

    一個比較笨的辦法,你再修改一下:
    SQL> select * from a;VALUE
    ----------
    a
    ab
    abc
    e
    abcdSQL> select y.value,a.value from (
      2  select child,min(length(parent)),min(rb)rb from(
      3  select a.value as child,(replace(b.value,a.value,'')) as parent,b.rowid as rb
      4  from a,a b
      5  where  instr(b.value,a.value)>0
      6  and length(replace(b.value,a.value,''))>0)
      7  group by child)x,a,a y
      8  where a.rowid(+)=x.rb and x.child(+)=y.value
      9  /VALUE      VALUE
    ---------- ----------
    a          ab
    ab         abc
    abc        abcd
    abcd       
    e
      

  2.   

    sorry,改了一下:
    SQL> select y.value,x.parent,a.value as child from (
      2  select parent,min(length(parent)),min(rb)rb from(
      3  select a.value as parent,(replace(b.value,a.value,'')) as child,b.rowid as rb
      4  from a,a b
      5  where  instr(b.value,a.value)>0
      6  and length(replace(a.value,b.value,''))>0)
      7  group by parent)x,a,a y
      8  where a.rowid(+)=x.rb and x.parent(+)=y.value
      9  /VALUE      PARENT     CHILD
    ---------- ---------- ----------
    a          a          ab
    ab         ab         abc
    abc        abc        abcd
    abcd                  
    e
      

  3.   

    前面的不看了:
    SQL> select a.value as child,x.parent from (
      2  select parent,min(length(parent)),min(rb)rb from(
      3  select a.value as parent,(replace(b.value,a.value,'')) as child,b.rowid as rb
      4  from a,a b
      5  where  instr(b.value,a.value)>0
      6  and length(replace(a.value,b.value,''))>0)
      7  group by parent)x,a
      8  where a.rowid=x.rb(+)
      9  /CHILD      PARENT
    ---------- ----------
    a          
    ab         a
    abc        ab
    e          
    abcd       abcSQL>
      

  4.   

    SQL> select * from a;VALUE
    ----------
    a
    ab
    abc
    e
    abcdSQL> select value child,(select max(value) from a where instr(b.value,a.value)>0
      2  and length(b.value)>length(a.value)) parent from a b;CHILD      PARENT
    ---------- ----------
    a
    ab         a
    abc        ab
    e
    abcd       abc
      

  5.   

    select X.a CHILD,(select max(Y.a)  
    from A Y where LEN(Y.a)<LEN(X.a) and 
    substring(X.a,1,LEN(Y.a))=Y.a  )
      PARENT from A X  order by a 
      

  6.   

    modify:select X.value CHILD,(select max(Y.value )  
    from A Y where LEN(Y.value )<LEN(X.value ) and 
    substring(X.value ,1,LEN(Y.value ))=Y.value   )
      PARENT from A X  order by value
      

  7.   

    select value,(select parent from (select CHILD,parent from b connect by prior CHILD=parent start with CHILD='a') where CHILD=value) parent from a;
      

  8.   

    select value child,(select max(value) from a where instr(b.value,a.value)>0
      2  and length(b.value)>length(a.value)) parent from a b;