23. 根据公司查找底下的所有部门,根据部门找对应的公司

Posted on 2015-12-02 10:42  zkx4213  阅读(343)  评论(0)    收藏  举报

/**

*   公司下存在子公司,子公司下存在部门,部门下存在子部门

*   公司下存在部门,部门下存在子部门

*   根据公司找底下的所有部门:select * from lbOrganization where fun_findComOrgId(ID)=公司ID;

*   根据部门对应的公司:select fun_findComOrgId(部门ID) from dual;

*/

create or replace function fun_findComOrgId(--查询所属公司或集团的id
p_orgid int--传人组织机构id
)
return int is

v_flag int:=0;--所属公司或集团的id
v_orgtype int;--组织机构类型变量,2为公司,3为部门
v_orgid int;--存放输入的组织机构id,或查出的

begin
v_orgid:=p_orgid;

while v_flag=0 loop
select orgtype into v_orgtype from lborganization where id=v_orgid;
if v_orgtype<=2 then
v_flag:=v_orgid;--v_flag=所属公司id
else
v_flag:=0;
end if;
select fid into v_orgid from lborganization where id=v_orgid;

end loop;

return (v_flag);

end;
/

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3