Oracle子句实现递归查询

直接上代码:产品

    表:resource_types(id, father_type_id,name)it

    select  t.id resource_type_id,      
   SUBSTR(translate(SYS_CONNECT_BY_PATH(translate(t.name,'-','tmp_'),'-'),'tmp_','-'),2) resource_type_name          
   from resource_types t    
   start with t.father_type_id is null          
   connect by t.father_type_id = prior t.idio

resource_type_id   resource_type_nameselect

2                            黑色金属矿产品
3                            黑色金属矿产品-铁矿石
4                            黑色金属矿产品-铁矿石-磁铁矿
 5                           黑色金属矿产品-铁矿石-赤铁矿
 6                           黑色金属矿产品-铁矿石-褐铁矿
 7                           黑色金属矿产品-铁矿石-菱铁矿
8                            黑色金属矿产品-锰矿石
9                            黑色金属矿产品-锰矿石-水锰矿
10                          黑色金属矿产品-锰矿石-褐锰矿
11                          黑色金属矿产品-锰矿石-软锰矿
12                          黑色金属矿产品-锰矿石-硬锰矿

 
co

相关文章
相关标签/搜索