用sql实现递归的查询

      主键    父节点     是否     名称            描述

                              叶子

                              节点    

    RES_CAT_ID     IS_LEAFNODE

  1 1_F 1 0 农业科学 农业科学 0 06-12月-12 03.52.09.074000 下午

  3 1_F 1 0 植物保护 植物保护 0 06-12月-12 03.52.34.545000 下午

  4 1_F 1 0 农作物 农作物 0 06-12月-12 03.52.50.804000 下午

  5 1 1 1 农业基础学科 农业基础学科 0 06-12月-12 03.53.24.490000 下午

  6 1 1 1 植物保护 植物保护 0 06-12月-12 03.53.43.328000 下午

  7 2 1 1 土壤学 土壤学 0 07-12月-12 10.34.10.163000 上午

  8 1_F 1 1 畜牧学 畜牧学 0 07-12月-12 10.38.43.331000 上午

2 1_F 1 0 农业基础科学 农业基础科学 0 06-12月-12 03.52.23.398000 下午

            RES_CAT_PAR_ID
第一列:RES_CAT_ID   第二列:RES_CAT_PAR_ID   第三列 : IS_LEAFNODE

查询某节点的所有叶子节点的数据
select t.res_cat_id, t.res_cat_name, t.res_cat_par_id
  from irc_res_cat t
 where t.res_cat_id <> '2' 
 start with t.res_cat_id = '2'
connect by prior t.res_cat_id = t.res_cat_par_id
       and t.is_del = '0'
       and t.is_leafnode = '1'
查询根目录下所有的叶子节点数据
select t.res_cat_id, t.res_cat_name, t.res_cat_par_id
  from irc_res_cat t
  where t.res_cat_par_id = '1_F' and t.is_leafnode = '1'

猜你喜欢

转载自pjzz6666.iteye.com/blog/1743546