这是一个书上的例了,说是可以得到以下结果。
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 ..
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 ..
CODE
----------
TYPE_RMARK
------------
A
BBB00
能不能设置成
code type_r
A BBB00
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);
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。