Pl/sql Foundation: Stratum Inquiry

Source: Internet
Author: User

ORACLE 10g New Hierarchy query operator Prior,connect_by_root

PRIOR

The connecy by condition of a hierarchical query needs to use prior to specify the parent node, and as an operator, the prior and add (+) minus (-) operations have the same precedence.

Class Query

Syntax: START with condition CONNECT by nocycle condition

START with the root of the specified hierarchy

CONNECT by the parent/child relationship of the specified hierarchy

Nocycle also returns the results of the query when a record of Connect by loop exists.

Condition ... PRIOR expr = expr or ... expr = PRIOR expr

Cases:

CONNECT BY last_name != 'King' AND PRIOR employee_id = manager_id ...
CONNECT BY PRIOR employee_id = manager_id and
PRIOR account_mgr_id = customer_id ...

Connect_by_root

Queries the hierarchical data for the specified root.

Example of CONNECT by clause

Define the relationship between the employee and the boss by using the Connect by clause.

SQL>SELECT employee_id, last_name, manager_id
FROM employees
CONNECT BY PRIOR employee_id = manager_id;

EMPLOYEE_ID LAST_NAME MANAGER_ID
----------- ------------------------- ----------
101 Kochhar 100
108 Greenberg 101
109 Faviet 108
110 Chen 108
111 Sciarra 108
112 Urman 108
113 Popp 108
200 Whalen 101

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.