I have a MYTYPE table in Oracle 10g representing a tree structure that looks something like this:
ID | PARENTID | DETAIL
I would like to select all rows in MYTYPE that are descendants of a specific ID so that I can create queries elsewhere, for example:
SELECT * FROM MYDETAIL WHERE MYTYPEID IN [all MYTYPE which are descendants of some ID];
What is an economical way to build a set of children, preferably without using PL / SQL?
Oracle did not support hierarchical ANSI syntax when using the recursive factoring subquery (CTE in SQL Server syntax) prior to 11g R2, so you need to use your own CONNECT BY syntax (supported since v2):
SELECT t.* FROM MYTABLE t START WITH t.parentid = ? CONNECT BY PRIOR t.id = t.parentid
, .
:
ID,ParentID Adjacency List. (.. , , ), (.. ). , Oracle CONNECT BY , . , -.
ID,ParentID
CONNECT BY
, Hierarchy Bridge, LEVEL . ID,DescendantID, , DescentantID . LEVEL . , , .
LEVEL
ID,DescendantID
, , Nested Set Materialized Path. . , , , . .
Oracle can execute recursive queries. Try exploring start with ... connect bysomething like this:
start with ... connect by
Select * from MYDETAIL Starting with PARENTID= 1 --or whatever the root ID is connect by PARENTID = prior ID
http://psoug.org/reference/connectby.html
Here are the details for the "connect by" functions in oracle. http://psoug.org/reference/connectby.html
Source: https://habr.com/ru/post/1785981/More articles:CakePHP how to addScript () from inside element? - phpSpring @Transactional - Can I override rollbackFor - javaJSON -> PHP array, complex search pointer path to a specific value - jsonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1785979/available-gis-toolkits&usg=ALkJrhg455SmjHMOhgpvx2JdZHPbH7hNwAincrease web2py productivity - databases and apache - performanceExcel 2007 - Compare 2 columns, find the corresponding values - excel-2007https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1785983/how-to-data-bind-to-the-css-top-left-width-and-height-of-a-dom-element&usg=ALkJrhhXUvpsa42wlSrJBgxHpvgELlxnDAAn object reference is required for a non-static field, method or property - javaJava object pointer with multiple threads - javaWhy does System.Net.Mail receive an “authentication failure” but System.Web.Mail does not? - .netAll Articles