Plsql Learning Road (3) Recursive query returns property structure

Source: Internet
Author: User

1.FUNCTION

FUNCTION Query_all (v_org_id number) RETURN Pl_json is

V_orglist Pl_json: = Pl_json;

V_temp Pl_json: = Pl_json;

V_total number: = 0;

V_parentorganizationname VARCHAR2 (100);

--Get basic information org_id this organization and spell the string

CURSOR V_qur_cur is

SELECT *

From Dfnd.dfnd_organizations do

WHERE do.organization_id = v_org_id;

--Get org_id An array of sub-organizations under this organization

CURSOR V_qurall_cur is

SELECT *

From Dfnd.dfnd_organizations do

WHERE do.parent_organization_id = v_org_id

Order BY Do.order_num;

BEGIN

For V_qur in V_qur_cur LOOP

V_orglist.set_value (' OrganizationId ', v_qur.organization_id);

V_orglist.set_value (' Organizationcode ', v_qur.organization_code);

V_orglist.set_value (' OrganizationName ', v_qur.organization_name);

V_orglist.set_value (' Parentorganizationid ',

V_QUR.PARENT_ORGANIZATION_ID);

V_orglist.set_value (' Organizationmanager ', ' 11 ');

IF v_qur.parent_organization_id is isn't NULL then

SELECT Do1.organization_name

Into V_parentorganizationname

From Dfnd.dfnd_organizations Do1

WHERE do1.organization_id = v_qur.parent_organization_id;

V_orglist.set_value (' Parentorganizationname ',

V_parentorganizationname);

END IF;

END LOOP;

For V_qurall in V_qurall_cur LOOP

V_total: = v_total + 1;

IF (v_total >= 1) Then

V_temp: = Query_all (v_qurall.organization_id);

V_orglist.add_list_item (' childorganizations ', v_temp);

END IF;

END LOOP;

RETURN v_orglist;

END Query_all;

2.PROCEDURE

PROCEDURE proc_query_all_organizations (P_request CLOB,

X_response out CLOB) is

V_api VARCHAR2 (+): = ' proc_query_all_organizations ';

V_response Pl_json: = Pl_json;

V_temp Pl_json;

V_orglist Pl_json: = Pl_json;

V_ORG_ID number;

BEGIN

SELECT do.organization_id

Into v_org_id

From Dfnd.dfnd_organizations do

WHERE do.parent_organization_id is NULL;

V_temp: = Query_all (v_org_id);

V_orglist.set_value (' orglist ', v_temp);

X_response: = V_orglist.to_json;

EXCEPTION

When OTHERS Then

ROLLBACK;

V_response.fail (' interface ' | | | v_api | | ' An error occurred, cause of error: ' | | SQLERRM);

X_response: = V_response.to_json;

END proc_query_all_organizations;

Plsql Learning Road (3) Recursive query returns property structure

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.