23. According to the company to find all the departments below, according to the department to find the corresponding company

Source: Internet
Author: User

/**

* Subsidiaries exist under the company, subsidiaries exist under the Department, there are sub-departments under the department

* Under the existing department of the company, there are sub-departments under the department

* Find all departments under the company: SELECT * from Lborganization where fun_findcomorgid (id) = Company ID;

* According to department corresponding company:Select FUN_FINDCOMORGID (department ID) from dual;

*/

Create or Replace function fun_findcomorgid (--Query the ID of the company or group that owns the
P_orgid int--successor Organization ID
)
return int is

V_flag int:=0;--The ID of the company or group in which it belongs
V_orgtype int;--organization type variable, 2 for company, 3 for department
V_orgid int;--Store input organization ID, or isolated

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=-owned company ID
Else
v_flag:=0;
End If;
Select FID to V_orgid from Lborganization where Id=v_orgid;

End Loop;

return (V_flag);

End
/

23. According to the company to find all the departments below, according to the department to find the corresponding company

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.