create or replace function getUnitFullName(deptid in varchar)
return varchar2 is
r varchar2(1024);
c int;
n varchar2(1024);
m varchar2(1024);
r_name varchar2(1024);
m_deptid varchar2(64);
begin
r := '';
select a.tree_level_num,a.tree_node
into c,m_deptid
from pstreenode a
where a.tree_name = 'DEPT_SECURITY'
and a.tree_node = deptid
and A.EFFDT = (SELECT MAX(A_ED.EFFDT)
FROM pstreenode A_ED
WHERE A.tree_node = A_ED.tree_node); select l.descr
into r_name
from ps_dept_tbl l
where l.deptid = m_deptid
and l.EFFDT = (SELECT MAX(D_ED.EFFDT)
FROM PS_DEPT_TBL D_ED
WHERE l.SETID = D_ED.SETID
AND l.DEPTID = D_ED.DEPTID); r:=r_name;
if c = 1 then
return r;
end if; select a.tree_level_num, a.parent_node_name, a.tree_node
into c, n, m
from pstreenode a
where a.tree_name = 'DEPT_SECURITY'
and a.tree_node = deptid
and A.EFFDT = (SELECT MAX(A_ED.EFFDT)
FROM pstreenode A_ED
WHERE A.tree_node = A_ED.tree_node);
while c <> 1 loop
select l.descr
into r_name
from ps_dept_tbl l
where l.deptid = n
and l.EFFDT = (SELECT MAX(D_ED.EFFDT)
FROM PS_DEPT_TBL D_ED
WHERE l.SETID = D_ED.SETID
AND l.DEPTID = D_ED.DEPTID);
r := r_name || '/' || r;
select a.tree_level_num, a.parent_node_name, a.tree_node
into c, n, m
from pstreenode a
where a.tree_name = 'DEPT_SECURITY'
and a.tree_node = n
and A.EFFDT = (SELECT MAX(A_ED.EFFDT)
FROM pstreenode A_ED
WHERE A.tree_node = A_ED.tree_node); end loop;
return r;
end getUnitFullName;