Concept of hierarchical query in Oracle

Source: Internet
Author: User

Concept of hierarchical query in Oracle syntax format: select [level], column, expr... from table [where condition] start with condition connect by [prior column1 = column2 | column1 = prior column2]; hierarchical queries are identified by the start with and connect by clauses: 1. The level keyword is optional, indicating the level, 1 indicating the root, 2 indicating the root child, and other identical rules. 2. A table can be followed by a From statement, but a view can only be a table. 3. The Where condition limits the rows returned by the query, but does not affect the hierarchy. It truncates the node, but the lower child of the truncated node is not affected. 4. Start with indicates the Start Node. This clause is required for a real hierarchical relationship, but not required. 5. connect by prior specifies the parent-child relationship. The prior location does not have to be after connect by. This is also required for a real hierarchy. Example: in a self-join, if the data volume is large, the Cartesian set may occur. SQL> -- the same table is treated as multiple tables using the table alias> select e. ename | 'The Boss is '| B. ename 2 from emp e, emp B 3 where e. mgr = B. empno; Result: In order to avoid this situation, the hierarchical query in Oracle is used. below, I will show an example of hierarchical query in the tree graph: SQL> -- execute hierarchical query SQL> select level, empno, ename, mgr 2 from emp 3 connect by prior empno = mgr 4 start with mgr is null 5 order by 1; Result:

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.