在同一表中尋找父類記錄。 css
--路徑級數sql
- 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;