这个函数意思是:通过参数查询对应数据。如果没有数据获取父级数据。直到找到对应数据位置。
 
  
  1. create or replace function get_tpl_mer(mer_id       varchar2, 
  2.                                        busi_type_id number) return varchar2 is 
  3.   v_result varchar2(100); 
  4.   cursor v_job is 
  5.     select g.group_code 
  6.       from info_group g 
  7.      start with g.group_code in 
  8.                 (select info_mer_addi.belong_group_code 
  9.                    from info_mer_addi 
  10.                   where info_mer_addi.mchnt_id = mer_id) 
  11.     connect by prior g.group_code = g.par_group_code; 
  12.   v_row   v_job%rowtype; 
  13.   v_count number; 
  14. begin 
  15.   select its.tpl_name 
  16.     into v_result 
  17.     from info_tpl_stmt its 
  18.    where its.tpl_id in (select itr.tpl_id 
  19.                           from info_tpl_rel itr 
  20.                          where itr.rec_stat = 0 
  21.                            and itr.rel_id = mer_id) 
  22.      and its.tpl_type = 1 
  23.      and its.busi_type_id = busi_type_id 
  24.      and rownum = 1; 
  25.   return v_result; 
  26. Exception 
  27.   when others then 
  28.     Dbms_Output.put_line(sqlerrm); 
  29.     v_result := ''
  30.     for v_row in v_job loop 
  31.       select count(0) 
  32.         into v_count 
  33.         from info_tpl_stmt its 
  34.        where its.tpl_id in 
  35.              (select itr.tpl_id 
  36.                 from info_tpl_rel itr 
  37.                where itr.rec_stat = 0 
  38.                  and itr.rel_id = v_row.group_code) 
  39.          and its.tpl_type = 2 
  40.          and its.busi_type_id = busi_type_id; 
  41.       if v_count > 0 then 
  42.         select its.tpl_name 
  43.           into v_result 
  44.           from info_tpl_stmt its 
  45.          where its.tpl_id in 
  46.                (select itr.tpl_id 
  47.                   from info_tpl_rel itr 
  48.                  where itr.rec_stat = 0 
  49.                    and itr.rel_id = v_row.group_code) 
  50.            and its.tpl_type = 2 
  51.            and its.busi_type_id = busi_type_id; 
  52.         exit; 
  53.       end if; 
  54.     end loop; 
  55.     return v_result; 
  56. end get_tpl_mer; 
  57.