Oracle uses the Start with... Connect By clause for Recursive queries

Source: Internet
Author: User


Oracle uses the Start with... Connect By clause to recursively query ORACLE. It provides an interesting function to connect by clause, which can sort the branches with a family tree structure. It applies to the structure of organizations or companies, financial account code, and so on. To use query traversal, you need to store data in the base table according to the hierarchy. For example, an organizational unit is a typical example. Implementation statement: SELECT column FROM table_name start with column = value connect by prior parent primary key = a friend on the Internet has provided a simple example. His example is as follows: -------------------------------------- Start... the Connect By clause recursive query is generally used for a table to maintain a tree structure. CREATE example TABLE: create table TBL_TEST (id number, NAME VARCHAR2 (100 BYTE), pid number default 0); INSERT test data: insert into TBL_TEST (ID, NAME, PID) VALUES ('1', '10', '0'); insert into TBL_TEST (ID, NAME, PID) VALUES ('2', '11', '1 '); insert into TBL_TEST (ID, NAME, PID) VALUES ('3', '20', '0'); insert into TBL_TEST (ID, NAME, PID) VALUES ('4', '12', '1'); insert into TBL_TEST (ID, NAME, PID) VALUES ('5', '123', '2 '); recursive select * from Root to tree end from TBL_TEST start with id = 1 connect by prior id = pid recursively select * from TBL_TEST start with id = 5 connect by prior pid = id author dhl004

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.