How should I write SQL recursive statements in oracle databases? The following is an example of using SQL recursive statements in oracle for your reference.
Example:
Pid id
A B
A c
A e
B b1
B b2
C c1
E e1
E e3
D d1
Specify pid = a and select
A B
A c
A e
B b1
B b2
C c1
E e1
E e3
SQL statement: select parent, child from test start with pid = 'A'
Connect by prior id = pid
Oracle SQL recursive query statement:
1. Table Structure
SQL> desc comm_org_subjection
Name Null? Type
-----------------------------------------------------------------------------
ORG_SUBJECTION_ID not null VARCHAR2 (32) subkey
ORG_ID not null VARCHAR2 (32)
FATHER_ORG_ID not null VARCHAR2 (32) parent key
LOCKED_IF not null VARCHAR2 (1)
START_DATE NOT NULL DATE
END_DATE DATE
EDITION_NAMEPLATE NUMBER (8)
CODE_AFFORD_IF VARCHAR2 (1)
CODE_AFFORD_ORG_ID not null VARCHAR2 (32)
CODING_SHOW_ID NUMBER (8)
BSFLAG VARCHAR2 (1)
MODIFI_DATE DATE
CREATOR_ID VARCHAR2 (32)
CREATE_DATE DATE
CREATOR VARCHAR2 (35)
2. Recursively search for all child nodes with the parent node org_id C6000000000001:
Select * from comm_org_subjection
Start with a.org _ id = 'c6000000000001'
Connect by prior a.org _ subjection_id = a. father_org_id
3. Recursively search for all the parent nodes under the subnode org_id C6000000000001:
Select org_id from comm_org_subjection
Start with a.org _ id = 'c6000000000001'
Connect by prior a. father_org_id = a.org _ subjection_id
Three Common SQL insert statements
Example of batch SQL statement execution
SQL Connection Methods
Three SQL paging statements
How to define an SQL primary key