这是一个书上的例了,说是可以得到以下结果。
code                  type_r
A                     bbb00
  aa                    ..   
    aaa                 ..
    aab                  ..   
  ab                    dd
   aba                  dd7             
B                      bbb55
  bb                     ..
   bbb                   ..----------但是我机子--------------.
运行结果如下:
CODE
----------
TYPE_RMARK
------------
A
BBB00B
BBB55
?????????????????????????????
求教怎么修改上面代码才能得到以下运行结果code                  type_r
A                     bbb00
  aa                    ..   
    aaa                 ..
    aab                  ..   
  ab                    dd
   aba                  dd7             
B                      bbb55
  bb                     ..
   bbb                   ..

解决方案 »

  1.   

    为应该用字段www记录层次关系.
      

  2.   

    还有就是怎么让运行结果,,显示的列不折行啊???
    CODE
    ----------
    TYPE_RMARK
    ------------
    A
    BBB00
    能不能设置成
    code              type_r
    A                  BBB00
      

  3.   

    select lpad(' ',2*(level-1))||type_code code,type_r 
    from type 
    start with type_code='A' or type_code = 'B' 
    connect by prior type_code=substr(type_code,1,length(type_code)-1);
    语法没有问题,原因出在数据类型上,将数据类型char该为varchar2,或修改select语句用ltrim和rtrim去掉空格即可:例如:
    select lpad(' ',2*(level-1))||rtrim(type_code) code,type_r 
    from type 
    start with rtrim(type_code)='A' or rtrim(type_code) = 'B' 
    connect by prior rtrim(type_code)=substr(rtrim(type_code),1,length(rtrim(type_code))-1);
      

  4.   

    将select lpad(' ',2*(level-1))||rtrim(type_code) code,type_r 中的lpad(' ',2*(level-1))||rtrim(type_code)的长度加以限制就能实现不折行,例如改为:select substr(lpad(' ',2*(level-1))||rtrim(type_code),1,20) code,type_r from ..
      

  5.   

    或用set linesize num将行设的足够长。比如:set linesize 5000;
      

  6.   

    找半天,才发现是数据类型问题。
    drop table type;
    create table type
    (
      type_code varchar2(5),
      type_r char(12),
      www char(1)
      );
    insert into type values('A','BBB00','w');
    insert into type values('AA','BA999BB','w');
    insert into type values('AAAA','BB88B','w'); 
    insert into type values('AAA','BBB77','w');  
    insert into type values('AAAAA','AABB66','w');
    insert into type values('B','BBB55','w');
    insert into type values('AB','BB44','w');
    insert into type values('BA','BBB22','w');
    insert into type values('ABB','ABBB11','w');
    commit;因为length 函数 对 char(5) ,不管数据库值长度多少,返回值都是 5。