a、类型表(类型ID、类型名称、父类型ID)t_protype(proclassid,TypeName,profclassid)
b、资源表(资源ID、类型ID、资源名称、适用科室)t_article(articleid,TypeID,articleName,re)
类型表有多层,类似于树状结构。 节点1--子节点1--孙节点1
--孙节点2
--孙节点3
子节点2--孙节点4
--孙节点5
...................................
如何通过类型ID,查找所有属于它的资源列表,其中包括所有属于它的子节点所包含的资源?各位大侠给点建议?
我是这么写的 (出错 ,各位大狭看看谢谢啦)
create function GetSunClass(@proclassid varchar(32))
returns @re table(proclassid varchar(32),level int)
as
begin
declare @l int
set @l=0
insert @re select @proclassid,@l
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.proclassid,@l
from t_protype a,@re b
where a.profclassid=b.proclassid and b.level=@l-1
end
return
end
go
-------------------------
--调用函数实现查询
select a.*,b.*
from t_protype a,GetSunClass('8a71e0fa1a3e009e011a46e9d73f0011') a1 --查询 proclassid='8a71e0fa1a3e009e011a46e9d73f0011' 及其所有子类的资源
,t_article b
where a.proclassid=a1.proclassid
and a1.proclassid=b.proclassid
报错 在调用GetSunClass('8a71e0fa1a3e009e011a46e9d73f0011') 语法出错````
b、资源表(资源ID、类型ID、资源名称、适用科室)t_article(articleid,TypeID,articleName,re)
类型表有多层,类似于树状结构。 节点1--子节点1--孙节点1
--孙节点2
--孙节点3
子节点2--孙节点4
--孙节点5
...................................
如何通过类型ID,查找所有属于它的资源列表,其中包括所有属于它的子节点所包含的资源?各位大侠给点建议?
我是这么写的 (出错 ,各位大狭看看谢谢啦)
create function GetSunClass(@proclassid varchar(32))
returns @re table(proclassid varchar(32),level int)
as
begin
declare @l int
set @l=0
insert @re select @proclassid,@l
while @@rowcount>0
begin
set @l=@l+1
insert @re select a.proclassid,@l
from t_protype a,@re b
where a.profclassid=b.proclassid and b.level=@l-1
end
return
end
go
-------------------------
--调用函数实现查询
select a.*,b.*
from t_protype a,GetSunClass('8a71e0fa1a3e009e011a46e9d73f0011') a1 --查询 proclassid='8a71e0fa1a3e009e011a46e9d73f0011' 及其所有子类的资源
,t_article b
where a.proclassid=a1.proclassid
and a1.proclassid=b.proclassid
报错 在调用GetSunClass('8a71e0fa1a3e009e011a46e9d73f0011') 语法出错````
解决方案 »
- 请问下sql语句!
- pl sql developer 中文本导入噐
- 所担负速度
- 关于ORACLE的一个行类型控由制抬输入数据向表中插入数据的过程程序
- 关于oracle中的自动列号如何调用,请教各位前辈?
- 再问:帮忙分析下这个错误,在做PROGRAM时遇到
- 怎么建此数据库表?
- 推荐几本学习ORACLE的书籍把?
- 请教一个触发器错误?
- 备份某Table时,而此Table中有自增字段(通过sequence实现的),在恢复时会不会有问题?
- 大姐求助:select to_char(0.5) from dual 结果是.5 ,如何得到0.5,前面有个零?
- 快崩溃了,oraclemyoracleTNSListener服务启动后又停止了,请教大家到底是什么原因啊?
connect by 可以查树形结构的
from t_protype a,t_article b
where a.proclassid=b.typeid
start with a.proclassid='8a71e0fa1a3e009e011a46e9d73f0011'
connect by prior a.proclassid=a.profclassid
connect by 用法
假设表a的结构
id upid name
021 上海
6503 021 虹口区
5666 021 徐汇区
01 北京
6666 01 朝阳区
5555 01 崇武区
想查出上海及下属所有区的纪录
select a.*
from a
start with id='021'
connect by prior id=upid