A字段 B字段 C字段
101 现金 现金
10101 文一路校区 现金_文一路现金
10103 玉皇山校区 现金_玉皇山校区
10104 下沙校区 现金_下沙校区
1010401 下沙校区一组 现金_下沙校区_下沙校区一组
1010402 下沙校区二组 现金_下沙校区_下沙校区二组
1010403 下沙校区三组 现金_下沙校区_下沙校区三组
102 银行存款 银行存款
10201 工行 银行存款_工行
。
。
。
。
怎样写才能得到C字段这样的数据结果
101 现金 现金
10101 文一路校区 现金_文一路现金
10103 玉皇山校区 现金_玉皇山校区
10104 下沙校区 现金_下沙校区
1010401 下沙校区一组 现金_下沙校区_下沙校区一组
1010402 下沙校区二组 现金_下沙校区_下沙校区二组
1010403 下沙校区三组 现金_下沙校区_下沙校区三组
102 银行存款 银行存款
10201 工行 银行存款_工行
。
。
。
。
怎样写才能得到C字段这样的数据结果
from t
start with length(a) = 3
connect by nocycle prior a = substr(a,0,3)
同意,使用sys_connect_by_path来写这个。详细用户可以参考
http://blog.csdn.net/inthirties/archive/2009/07/08/4331685.aspx
:-),牛人呢。有时间到你的博踩踩
你的oracle 版本是。
这个思路是对的,用树形结构和sys_connect_by_path来显示,
但是处理上有些小问题, substr(a,0,3) 方法参数不对 用下面的试试。SQL>select * from sample_t1;
SQL> select * from sample_t1;
A B
---------------------------------------- --------------------------------------------------------------------------------
101 现金
10101 文一路校区
10103 玉皇山校区
10104 下沙校区
1010401 下沙校区一组
1010402 下沙校区二组6 rows selected[code]SQL> col a format a10;
SQL> col b format a20;
SQL> with temp as
2 (select a, b, decode(length(a), 3, '', substr(a, 1, length(a)-2)) p from sample_t1)
3 select a, b, substr(sys_connect_by_path(b, '-'),2) c from temp start with p is null connect by prior a = p;
A B C
---------- -------------------- --------------------------------------------------------------------------------
101 现金 现金
10101 文一路校区 现金-文一路校区
10103 玉皇山校区 现金-玉皇山校区
10104 下沙校区 现金-下沙校区
1010401 下沙校区一组 现金-下沙校区-下沙校区一组
1010402 下沙校区二组 现金-下沙校区-下沙校区二组
6 rows selected[/code]
2 (select a, b, decode(length(a), 3, '', substr(a, 1, length(a)-2)) p from sample_t1)
3 select a, b, substr(sys_connect_by_path(b, '-'),2) c from temp start with p is null connect by prior a = p;
A B C
---------- -------------------- --------------------------------------------------------------------------------
101 现金 现金
10101 文一路校区 现金-文一路校区
10103 玉皇山校区 现金-玉皇山校区
10104 下沙校区 现金-下沙校区
1010401 下沙校区一组 现金-下沙校区-下沙校区一组
1010402 下沙校区二组 现金-下沙校区-下沙校区二组
6 rows selected