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') 语法出错````

解决方案 »

  1.   

    oracle里有start with 
        connect by 可以查树形结构的
      

  2.   

    select  a.*,b.*  
      from  t_protype  a,t_article b
         where a.proclassid=b.typeid 
           start with a.proclassid='8a71e0fa1a3e009e011a46e9d73f0011' 
           connect by prior a.proclassid=a.profclassid
      

  3.   

    start with 
    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
      

  4.   

    select count(*) from t_protype start with proclassid='8a71e0fa1a3e009e011a46e9d73f0011' connect by prior proclassid = profclassid正解谢谢```马上揭贴```ORACLE 不是很熟悉``