当前位置:主页>仓库管理软件> 列表

orcale 高手请教 找金蝶财务软件破解版

仓库管理软件版1楼: 小弟在orcale中写SQL有个问题请教各位:库结构为是
自动编号 父编号 名称
001 R 生产运行部
002 001 一号车间
003 001 二号车间
004 002 办公室

通过SQL得到的结果为:
自动编号 名称
001 生产运行部
002 生产运行部\一号车间
003 生产运行部\二号车间
004 生产运行部\一号车间\办公室
请各位老大,帮帮忙,在线等待。谢谢

2楼: select 编号,concat(concat(select 名称 from yourtable where 父编号=编号),''\''),名称) from yourtable order by 编号
意思差不多,试试看吧 如金蝶财务软件破解版

3楼: skyccf:
老大,你的SQL在SQLTools中执行报错呀,ORA-00936: missing expression
而且select 名称 from yourtable where 父编号=编号是执行记录为空.

4楼: select t2.id,t2.ParentId,t1.Name+''\''+t2.Name as Name from test t1,test t2 where --t2.ParentId=t1.id
charindex(t2.ParentId,t1.id)>0 继续循环,应该可以得到结果

5楼: select distinct(id),Name from (


select t3.id,t1.Name+''\''+t2.Name+''\''+t3.Name as Name from test t1,test t2,test t3
where charindex(t2.ParentId,t1.id)>0 and charindex(t3.ParentId,t2.id)>0
union
select t2.id,t1.Name+''\''+t2.Name as Name from test t1,test t2
where charindex(t2.ParentId,t1.id)>0
union
select t.id,t.Name from test t where t.ParentId=''R''
) as sun 暂时就这样了,更好的办法还没想到

6楼: 自动编号 父编号 TreeItem 名称
001 R 01 生产运行部
002 001 0101 一号车间
003 001 0102 二号车间
004 002 010101 办公室
005 003 010201 1办公室 如果表结构是这样的,实现是不是要容易点呢

仓库管理软件版7楼: 老大,我要解释一下,我是在Oracle数据库中,并且我的层次是无限级的,不是固定三级

8楼: 最近在论坛上,经常会看到关于分组后字段拼接的问题,
大概是类似下列的情形:
SQL> select no,q from test
2 /

NO Q
---------- ------------------------------
001 n1
001 n2
001 n3
001 n4
001 n5


002 m1
003 t1
003 t2
003 t3
003 t4
003 t5
003 t6

12 rows selected

最后要得到类似于如下的结果:
001 n1;n2;n3;n4;n5
002 m1
003 t1;t2;t3;t4;t5;t6

通常大家都认为这类问题无法用一句SQL解决,本来我也这么认为,可是今天无意中突然有了灵感,原来是可以这么做的:
前几天有人提到过sys_connect_by_path的用法,我想这里是不是也能用到这个方法,如果能做到的话,不用函数或存贮过程也可以做到了;要用到sys_connect_by_path,首先要自己构建树型的结构,并且树的每个分支都是单根的,例如1-〉2-〉3-〉4,不会存在1-〉2,1-〉3的情况;
我是这么构建树,很简单的,看下面的结果就会知道了:
SQL> select no,q,rn,lead(rn) over(partition by no order by rn) rn1
2 from (select no,q,row_number() over(order by no,q desc) rn from test)
3 /

NO Q RN RN1
---------- ------------------------------ ---------- ----------
001 n5 1 2
001 n4 2 3
001 n3 3 4
001 n2 4 5
001 n1 5
002 m1 6
003 t6 7 8
003 t5 8 9
003 t4 9 10
003 t3 10 11
003 t2 11 12
003 t1 12

12 rows selected

有了这个树型的结构,接下来的事就好办了,只要取出拥有全路径的那个path,问题就解决了,先看no=‘001’的分组:
select no,sys_connect_by_path(q,'';'') result from
(select no,q,rn,lead(rn) over(partition by no order by rn) rn1
from (select no,q,row_number() over(order by no,q desc) rn from test)
)
start with no = ''001'' and rn1 is null connect by rn1 = prior rn
SQL>
6 /

NO RESULT
---------- --------------------------------------------------------------------------------
001 ;n1
001 ;n1;n2
001 ;n1;n2;n3
001 ;n1;n2;n3;n4
001 ;n1;n2;n3;n4;n5

上面结果的最后1条就是我们要得结果了
要得到每组的结果,可以下面这样


代码:--------------------------------------------------------------------------------
select t.*,
(
select max(sys_connect_by_path(q,'';'')) result from
(select no,q,rn,lead(rn) over(partition by no order by rn) rn1
from (select no,q,row_number() over(order by no,q desc) rn from test)
)
start with no = t.no and rn1 is null connect by rn1 = prior rn
) value
from (select distinct no from test) --------------------------------------------------------------------------------


SQL>
10 /

NO VALUE
---------- --------------------------------------------------------------------------------
001 ;n1;n2;n3;n4;n5
002 ;m1
003 ;t1;t2;t3;t4;t5;t6

对上面结果稍加处理就可以了,希望对大家有帮助:)

9楼: ORACLE有一个命令可以完成

10楼: 呵呵,还有没有其它的办法了,zhanggx请问这个命令是什么哟