Oracle Cartesian operations

Source: Internet
Author: User

Oracle recursive query and deletion of parent-child relationship records
The database often processes records of parent-child relationships. In oracle, you can use a query statement to retrieve all the sub-records at a time. Example: t1 t11 t111 t1111 t12 t121 t1211 db data field: task_id task_name t. parent_task_id 000001 t1 *** 000002 t11 000001 000005 t12 000001 000003 t111 000002 000004 t1111 000003 000006 t121 000005 000007 t1211 000006 query statement: select t. task_id, t. task_name, t. parent_task_id from t_task t start with task_id = '000000' connect by prior task_id = parent_task_id; the result is: task_id task_name t. parent_task_id 000001 t1 000002 t11 000001 000003 t111 000002 t1111 000004 000003 t12 000005 000001 t121 000006 t1211 000005 strat with specified level start condition, that is to say, the row that meets this condition can be used as the join condition between the top-level connect by prior of the hierarchy tree, that is, what kind of row is the sub-row of the upper-level row (self-join condition) select level, id, name, parentid from temptable2 connect by prior id (child-layer column) = parentid (top-level column) start with id = 1 Delete parent-child relationship record: delete from t_task where task_id in (select task_id from t_task connect by prior task_id = parentid start with task_id = '000000'); author shaozhen

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.