ORACLE recursive query

Source: Internet
Author: User

Since we will look at ORACLE recursive queries, we should be clear about what recursion means. Here I will not explain it more, but I will just give a brief introduction.

The so-called recursive query makes the data structure in the data table conform to the basic conditions of recursive query, that is, the table has the ID and PID (node number, parent node number) if the data is displayed in the UI, it should be one or more trees.

We need to explain the process of recursively querying the child or parent node of this node with one node.

Recursive query syntax:

 

Where condition 4

 

The table structure http://www.cnblogs.com/wanghonghu/archive/2012/08/31/2665945.html below

 ()                   (( BYTE)           ()
); SC_DISTRICT SC_DISTRICT SC_DISTRICT (IID));
SC _DISTRICT (IID, INAME) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ) (, SC _DISTRICT (IID, PARENT_ID, INAME, BZ )(,,);

If

 

-- Query subnodes in Pyeongchang County

SELECT * FROM SC _DISTRICT
Start with iname = 'pyeongchang Sha'
Connect by prior iid = PARENT_ID

-- Query the parent node of Pyeongchang County

SELECT * FROM SC _DISTRICT
Start with iname = 'pyeongchang Sha'
Connect by prior PARENT_ID = IID

-- Only filters out subnodes whose node BZ is 0, but does not filter out subnodes whose node BZ is 0 (this is worth noting ),

-- Currently, you can filter subnodes whose BZ is 0.

SELECT * FROM SC _DISTRICT WHERE BZ = 0
Start with iname = 'pyeongchang Sha'
Connect by prior PARENT_ID = IID

-- This method not only filters out nodes with BZ 0, but also does not traverse the subnodes of this node.

SELECT * FROM SC _DISTRICT START WITH INAME = 'pyeongchang County'
Connect by prior PARENT_ID = iid and bz = 0

If you know more about recursive methods, the above methods are easy to understand.

Related Article

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.