Oracle recursive query

Source: Internet
Author: User

1. Grammatical structure:

Select... start with...connect by...prior

For example: there is a unit (unit) Table with three field IDs, Name,parentid (unit ID, Unit name, ancestor's unit ID)

1.1 Query all units below the unit

Select  from unit t start with t.id=' units ID' connect by prior  t.id= T.parentid

1.2 Query all units above the unit

Select  from unit t start with t.id=' units ID' connect by  t.id= Prior T.parentid

2. Remark:

Start with logo from where to start checking the  prior  logo up or down.

3. Expand:

Recursive queries tend to be sorted with siblings, which is what we'll use: ORDER siblings by

For example: querying all units and sorting the units of the same level by phonetic Alphabet

Select  from unit t start with t.id=' units ID' connect by prior  t.id= T.parentid ORDER sibli NGS by Nlssort (T.name,'nls_sort=schinese_pinyin_m')

Oracle recursive query

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.