码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-12-02 12:10:07      阅读:147      评论:0      收藏: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;
/

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

标签:

原文地址:http://www.cnblogs.com/zkx4213/p/5012265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!