在同一表中寻找父类记录。
--路径级数
- select count(*)+1 into v_data from css.css_organizaioninfo t
- start with -- start with 是递归入口
- t.org_id = v_record.org_id -- 指明入口条件
- connect by prior -- prior 前序遍历 ;不写,默认不递归查询
- tt.parter = t.org_id;
- param_path_level := v_data; -- 级联条件(通过那个字段相连)
- create or replace function f_find_father(p_value VARCHAR2) return VARCHAR2 is
- v_str VARCHAR2(60) := p_value;
- procedure p_get_father_str(p_son in varchar2,p_str in out varchar2) as
- begin
- for i in(select parter from css.css_organizaioninfo where org_id = p_son and parter != org_id) loop
- if instr(p_str ||'_','_'||i.parter ||'_') = 0 then
- p_str := i.parter || '_' ||p_str;
- p_get_father_str(i.parter,p_str);
- end if;
- end loop;
- end;
- begin
- p_get_father_str(p_value,v_str);
return v_str;end;