Filtered hierarchical data - previous available ancestor?
I'm trying to find a solution to a problem with hierarchical data and the concept of the closest available ancestor – my platform is gr 10, 2 and 11 GR 2. I give myself a few hierarchical data (in its simplest form it is in the form ID, NAME, PARENT_ID, where of the PARENT_ID since ID links).
For example:
with qryData like)
Select 1 as ID, 'Bert' as NAME, to_number (null) as PARENT_ID from dual union
Select 2 as ID, 'Brand', 1 double Union
Select 3 as ID, 'Brenda', 1 double Union
Select option 4 as ID, 'Mike', 3 double Union
Select 5 as ID, 'Steve', 4 double Union
Select 6 as ID, 'John', 2 double Union
Select 7 as ID, 'Jo', 6 double Union
Select ID, "Jim", 2 double Union 8
Select 9 as ID, 'Jane', the double 7
)
Select q.*, sys_connect_by_path (ID, ' /') ID_PATH
of qryData q
Start by parent_id is null
Connect ID PARENT_ID = prior
/
ID NAME PARENT_ID ID_PATH
---------- ------ ---------- ----------------
1 Bert 1
2. Mark 1/1/2
6 Jean 2/1/2/6
7 Jo 6/1/2/6/7
Jane 9 7/1/2/6/7/9
8 Jim 2/1/2/8
3 Brenda-1/1/3
4 mike 3/1/3/4
5 Steve 4/1/3/4/5
In reality, this data set can be several thousand rows with dozens of levels of nesting, the several nodes to start without parent but especially often filtered, so some arbitrary lines are missing. When this happens, I need to find the closest available ancestor that appears in the list. "The closest available ancestor" is closest relationship to ancestor in your family tree which still exists in the filtered list found from parent, then upward contuniing to grandparent, great-grandparent... nth grandparent grand until an ancestor is found.
For example:
ID NAME PARENT_ID ID_PATH AVAIL_ANCESTOR_ID
---------- ------ ---------- ------------- -----------------
1 Bert 1
Jean 6 2 1 1/2/6
Jim 8 2 1 1/2/8
Jane 9 7 6 1/2/6/7/9
Brenda 3 1 1 1/3
Steve 5 4 3 1/3/4/5
For example. Who is Steve closest ancestor in the filtered list?
Steve's family tree is: / Bert/Brenda/Mike/Steve
Mike (ID = 4) is not in the filtered list, so we move on Brenda, what is. Brenda, ID = 3, so ANCESTOR_ID = 3
I have access to the original table, so that can join the list filtered to the full table, I can also ask other columns (such as ROWID, and ROWNUM, LEVEL SYS_CONNECT_ROOT) to be included in the filtered set. I tried various methods to achieve this, but all seem to be quite poor in performance (the columns ID and PARENT_ID indexed as appropriate) or does not quite give the correct result, such as...
1. the analysis of the ID_PATH and the treewalking on this basis and to join the list...
Select distinct CUSTOMER_ID, regexp_substr (ID_PATH, "[^ /] +', 1, level") as ANCESTOR_ID
of qryData
connect regexp_substr (ID_PATH, "[^ /] +', 1, level") is not null
2 anti-assemblage to return to the full list in order to identify the missing elements, then for those treewalking.
3 write a function that return treewalks.
It of a difficult problem, so someone can think a solution that works well? Ideally, I try to find a SQL based solution?
Hello
paulzip wrote:
It is a clever solution! The only problem I have is that I wouldn't be able to generate "good_id_path" as part of the filtered list, filtering is not done by me and is done once the id_path is generated. I have to join the most complete list list filtered back to generate, unless there is a tweak to do?
I see it; You are given connect_by_results (with id_path), and that's what you have to work with, in addition to the original table.
Here's one way:
SELECT d.id d.name, d.parent_id, d.id_path
MIN (a.id) DUNGEON (DENSE_RANK LAST ORDER BY a.id_path) AS avail_ancestor_id
OF connect_by_results d
LEFT OUTER JOIN connect_by_results has the d.id_path AS a.id_path. '/%'
GROUP BY d.id d.name, d.parent_id, d.id_path
ORDER BY d.id_path
;
The fastest way depends on a lot of things, some may not be known until the moment of execution. The query above could be better if the number of rows in the result set is small, but you don't know anything else about them (for example, if all have a common ancestor).
Tags: Database
Similar Questions
-
Hierarchical data, how to aggregate over levels in hierarchical query?
Hello
I hope someone can help me.
I held in a data table ("" what part was built in what other part of when when? "')
ID parent_id build_in build_out
1 NULL NULL NULL
2/1 2010 2012
3 2 2011 2013
4 2 2013 NULL
What are the parts is stored in a separate table.
Now I want to know when when which part was built in the first level, in the example, I want to know that
1 was simply a part of 1
2 was part of 1 between 2010 and 2012
3 was part of 1 between 2011 and 2012
4 has never been a part of 1
I tried several approaches - if there is a fixed number of levels between the types, I am interested I can do using joins and more/less (similarly as some nvl). Unfortunately this is not always the case (some parts appear on several levels).
If I'm only interested in the parts that are never deleted, I can get by using a style of connect request and get the current configuration. But I can't seem to understand the time connecting part to the high level in such a query, or even filtering absurd combinations (like "4 in 1" in the example above). I could deal with the data recovered outside the database, but I prefer not.
Is there a way to obtain the hierarchical data with an aggregate (min, max) for all levels?What version of Oracle you are on?
In 11.2.x, you can use the recursive subquery factoring. Something like
with t (id, parent_id, build_in, build_out) as ( select 1, null, null, null from dual union all select 2, 1, 2010, 2012 from dual union all select 3, 2, 2011, 2013 from dual union all select 4, 2, 2013, null from dual ) , c1 (root_id, id, parent_id, build_in, build_out) as ( select id, id, parent_id, 0, 9999 from t where parent_id is null union all select root_id, t.id, t.parent_id , greatest(nvl(t.build_in,0), nvl(b.build_in,0)) , least(nvl(t.build_out,9999), nvl(b.build_out,9999)) from c1 b, t where b.id = t.parent_id ) select * from c1 where build_in < build_out ; ROOT_ID ID PARENT_ID BUILD_IN BUILD_OUT ------- ----- ---------- --------- ---------- 1 1 0 9999 1 2 1 2010 2012 1 3 2 2011 2012
With a hierarchical query by using the syntax connection, you could do something like
select * from ( select connect_by_root id as root, id , greatest(nvl(build_in,0), nvl(prior build_in,0)) as max_in, least(nvl(build_out,9999), nvl(prior build_out,9999)) as min_out from t start with parent_id is null connect by parent_id = prior id ) where max_in < min_out ;
but it is not powerful enough. This version compares the dates between a current and previous levels, but the recursive subquery is to compare the dates in the current level for the winners of the comparisons to the previous level. Not sure if it's an important distinction for your needs, however.
If you are on 11.2 I advise to use the recursive subquery factoring. If this isn't the case, you can try the link by version.
Kind regards
Bob -
Carbon X 1 with the date of availability of touch screen
Carbon X 1 with the date of availability of touch screen?
Welcome to the community.
The X1CT seems to be available to order online now. You can right-click on the link to the Lenovo store top shop.
Kind regards.
-
How to remove hierarchical data?
Hello
I have a table with hierarchical data. I want to remove the data based on a condition, but maybe that this condition is present only in the upper hierarchy.
In my example, I have identified by id lines and a changed_by containing the id of the row that has replaced (invalidated) this line. Of these, I want to delete data where descr in end-nodes is 'A '.
Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
DROP TABLE test_del;
CREATE TABLE test_del)
CONSTRAINT pk_del PRIMARY KEY (id)
id NUMBER
changed_by NUMBER
CONSTRAINT fk_del
REFERENCES test_del (id)
, descr VARCHAR2 (10)
)
/
INSERT INTO test_del (id, changed_by, descr)
VALUES (3, NULL, 'A');
INSERT INTO test_del (id, changed_by, descr)
VALUES (2,3, 'A');
INSERT INTO test_del (ID, changed_by, descr)
VALUES (1, 2, NULL);
INSERT INTO test_del (id, changed_by, descr)
VALUES (6, NULL, 'A');
INSERT INTO test_del (id, changed_by, descr)
VALUES (5.6, 'A');
INSERT INTO test_del (id, changed_by, descr)
VALUES (10, 'B', NULL);
INSERT INTO test_del (id, changed_by, descr)
VALUES (9, 10, 'B');
INSERT INTO test_del (id, changed_by, descr)
VALUES (8,9, 'B');
COMMIT;
SELECT *.
OF test_del
CONNECT BY PRIOR ID = changed_by
START WITH descr = 'A' changed_by AND IS NULL;
ID CHANGED_BY DESCR
---------- ---------- ----------
3 A
2 3
1 2
6 A
3 p
DELETE FROM test_del WHERE the descr = "A";
ORA-02292: integrity constraint (FE. FK_DEL) violated - book of the foundlingOf course, I get ORA-02292 in this case, but how can I write a correct statement that deletes the data displayed by the select?
Concerning
Marcus
You must follow the hierarchy:
DELETE FROM test_del
WHERE ROWID IN)
SELECT THE ROWID
OF test_del
CONNECT BY PRIOR ID = changed_by
START WITH descr = "A".
AND changed_by IS NULL);
-
Problem with the filtering of data
Hello!
I have a problem with filtering the data in my table and don't know how to solve it properly.
I created a tabular presentation, my table, a few text fields that are used as input for the various columns of the filter and a filter button that submits the page.
The problem appeared when I try to filter a column that has null values in the table and is editable... it's that I have found.
When I press the button I get no line, although there should be some.It's the submitted query:
Select
"MSR_PRD_ID,"
"SRC_STM_ID,"
"ID."
"ISIN"
...
of ' #OWNER # '. " IZV_SLOG_DET ".
WHERE
Lower (MSR_PRD_ID) = low (nvl (: P7_X_MSR_PRD_ID, MSR_PRD_ID)) and
Lower (SRC_STM_ID) = low (nvl (: P7_X_SRC_STM_ID, SRC_STM_ID)) and
lower (ISIN) = low (nvl (: P7_X_ISIN, ISIN)) and
...
The nvl function is used so that if the user leaves the field blank it filters by fields that have entry only.
Does anyone know how I could get around this?
Kind regardsIvan
LOWER (NVL (ISIN, 'Y')) = LOW (NVL (: P7_X_ISIN, BASS (NVL (ISIN, 'Y'))))
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Apress.com/9781430235125
https://Apex.Oracle.com/pls/Apex/f?p=31517:1
http://www.Amazon.de/Oracle-Apex-XE-Praxis/DP/3826655494
-------------------------------------------------------------------
-
Filtering the data in row based on the setting
Hello
I have a report with the following columns:No Name mgr_role1 mgr_role_value dir_role2 dir_role_value super_role3 super_role3_value ...... 1 abc Manager 1111 Director 2222 Supervisor 4444
We can create any parameters and filters the data like this in Discoverer?I want to pass a parameter with LOV or enterable field i.e Role: If Role = 'Manager' I want to filter dir_role2,dir_role_value,super_role3,super_role3_value If Role = 'Director' I want to filter dir_role1,dir_role_value1,super_role3,super_role3_value If Role = 'Supervisor' I want to filter dir_role1,dir_role_value1,super_role2,super_role2_value
Thank you
KiranHello
You should probably create a condition for each column you are filtering on. Something like:
dir_role1 = CASE WHEN: role IN ('supervisor', 'Director') THEN: dir_role ELSE dir_role1 END
so that the column is filtered only when the role is supervisor or Director.
Rod West
-
Download SampleProjects - 60 x .zip previously available on Bea dev2dev?
Dear community,
I'm looking for the SampleProjects - 60 x .zip file previously available on Bea dev2dev and that is notably referenced in http://docs.oracle.com/cd/E13174_01/alui/devdoc/docs60/Plumtree_Development_Environment/UI_Customization/PlumtreeDevDoc_DevEnv_InstallSamples_Java.htm.
I know that it is a fairly old Portal version, but I need now to make a few adaptations and the above file would be very useful. I shopped on the Inet and also on the sites of the Oracle, but I couldn't find any download site.
Any help would be greatly appreciated.There is a post on the RTO about three years that linked to a site that hosted it. It seems to still be there:
http://joelcollins.posterous.com/sample-projects-60-zip-file
-Mike Headley, WCI Developer Support
-
Performance tab data - not available
I am running vCentre 4.0.0 with SQL Server 2008 installed on the same server. I am able to view the summary of 1 day for all virtual machines and hosts, but when you try to look at the other options, I get a message indicating that no data is available. When you go to advanced options, the received message is "performance data are currently not available for this entity."
Concerning
Dan
Verify that SQL Server agent is running.
-
Download all dates previous 80 from the current date.
Hi all
If I get start date and number of days as parameters to query then query must return all dates previous 80 starts to count.
As of now, we can hard code number of the days and begin to reach this day. Please let me know how I can achieve this.
Thanks and greetings
Nana AKkivalli.That should do it...
DTYLER_APP@pssdev2> var startdate varchar2(10) DTYLER_APP@pssdev2> var numdays number DTYLER_APP@pssdev2> exec :startdate := '01/09/2011' PL/SQL procedure successfully completed. STARTDATE -------------------------------- 01/09/2011 DTYLER_APP@pssdev2> exec :numdays := 10 PL/SQL procedure successfully completed. NUMDAYS ---------- 10 DTYLER_APP@pssdev2> DTYLER_APP@pssdev2> SELECT 2 TO_DATE(:startdate,'dd/mm/yyyy') - (rownum - 1) dt 3 FROM 4 dual 5 CONNECT BY 6 LEVEL <= :numdays 7 / DT -------- 01-09-11 31-08-11 30-08-11 29-08-11 28-08-11 27-08-11 26-08-11 25-08-11 24-08-11 23-08-11 10 rows selected.
-
Populate a list with the data previously collected
I want to populate a drop-down list with the data previously collected in the same form. How can I do this?
There are a variety of ways. For example, if 'stooges' is a drop-down list and 'stoogeName' is a text field, you can place the JavaScript code depending on the output of "stoogeName," event
Form1.Page1.Subform1.stoogeName::exit - (JavaScript, client)
Form1.Page1.Subform1.Stooges.AddItem (this.) RawValue);
Steve
-
Problem (hierarchical data) resolved by using SQL
Hi I have hierarchical data stored in a table with 3 columns
Item1, item2, relationship
relationship column defines if the element1 is parent of item2 or item1 item2 Chile
I have a fourth column in the same table indicating the entire hierarchy of the family separated by colons;
example: a1, a2, child then output will be a1:a2.
I have tried a lot of things to do with a sql but failed and finally did using the recursive function
Hoping someone can solve the problem in sql
You will find examples of data to work with as well as the desired result:
Kind regardsselect 'p1' as element1, 'p2' as element2, 'parent' as relationship, 'p1' as output from dual union all select 'p2', 'p1', 'child', 'p1:p2' from dual union all select 'p1', 'p3', 'parent', 'p1' from dual union all select 'p3', 'p1', 'child', 'p1:p3' from dual union all select 'p2', 'p4', 'parent', 'p1:p2' from dual union all select 'p4', 'p2', 'child', 'p1:p2:p4' from dual union all select 'p2', 'p5', 'parent', 'p1:p2' from dual union all select 'p5', 'p2', 'child', 'p1:p2:p5' from dual union all select 'p3', 'p6', 'parent', 'p1:p3' from dual union all select 'p6', 'p3', 'child', 'p1:p3:p6' from dual union all select 'p5', 'p7', 'parent', 'p1:p2:p5' from dual union all select 'p7', 'p5', 'child', 'p1:p2:p5:p7' from dual union all select 'p5', 'p8', 'parent', 'p1:p2:p5' from dual union all select 'p8', 'p5', 'child', 'p1:p2:p5:p8' from dual union all select 'b1', 'b2', 'parent', 'b1' from dual union all select 'b2', 'b1', 'child', 'b1:b2' from dual union all select 'b2', 'b3', 'parent', 'b1:b2' from dual union all select 'b3', 'b2', 'child', 'b1:b2:b3' from dual union all select 'c1', 'c2', 'parent', 'c1' from dual union all select 'c2', 'c1', 'child', 'c1:c2' from dual union all select 'c1', 'c3', 'parent', 'c1' from dual union all select 'c3', 'c1', 'child', 'c1:c3' from dual union all select 'c3', 'c5', 'parent', 'c1:c3' from dual union all select 'c5', 'c3', 'child', 'c1:c3:c5' from dual union all select 'c3', 'c6', 'parent', 'c1:c3' from dual union all select 'c6', 'c3', 'child', 'c1:c3:c6' from dual union all select 'c3', 'c7', 'parent', 'c1:c3' from dual union all select 'c7', 'c3', 'child', 'c1:c3:c7' from dual union all select 'a1', null, 'parent', 'a1' from dual
Amitdon't worry, I fixed it...
with t as( select 'p1' as element1, 'p2' as element2, 'parent' as relationship from dual union all select 'p2', 'p1', 'child' from dual union all select 'p1', 'p3', 'parent'from dual union all select 'p3', 'p1', 'child' from dual union all select 'p2', 'p4', 'parent' from dual union all select 'p4', 'p2', 'child' from dual union all select 'p2', 'p5', 'parent' from dual union all select 'p5', 'p2', 'child' from dual union all select 'p3', 'p6', 'parent' from dual union all select 'p6', 'p3', 'child' from dual union all select 'p5', 'p7', 'parent' from dual union all select 'p7', 'p5', 'child' from dual union all select 'p5', 'p8', 'parent' from dual union all select 'p8', 'p5', 'child' from dual union all select 'b1', 'b2', 'parent' from dual union all select 'b2', 'b1', 'child' from dual union all select 'b2', 'b3', 'parent' from dual union all select 'b3', 'b2', 'child' from dual union all select 'c1', 'c2', 'parent' from dual union all select 'c2', 'c1', 'child' from dual union all select 'c1', 'c3', 'parent' from dual union all select 'c3', 'c1', 'child' from dual union all select 'c3', 'c5', 'parent' from dual union all select 'c5', 'c3', 'child' from dual union all select 'c3', 'c6', 'parent' from dual union all select 'c6', 'c3', 'child' from dual union all select 'c3', 'c7', 'parent' from dual union all select 'c7', 'c3', 'child' from dual union all select 'a1', null, 'parent' from dual ), p as ( select * from t where relationship='parent') ,q as ( select * from t where relationship='child' ) select element1,element2,relationship,path from (select path,element1,'parent' relationship,element2 from ( select path,element1,element2,row_number() over (partition by element1,element2 order by length(path) desc) rnum from ( select ltrim(sys_connect_by_path(element1,':'),':') path,element1,element2 from p connect by prior element2=element1 )) where rnum=1 union all select path,element1,'child' relationship,element2 from ( select path,element1,element2,row_number() over (partition by element1,element2 order by length(path) desc) rnum from ( select ltrim(connect_by_root element2||sys_connect_by_path(element1,':'),':') path,element1,element2 from q connect by prior element1=element2 )) where rnum=1)
Ravi Kumar
-
Hello!
I need to create data model that describes hierarchical data in table t (something like this in sql: select * t log in prior t.id_parent = t.id).
How to describe with JDeveloper?
(Then it will be used in the table of the tree)
JDeveloper 11.1.1.1
Thank you!Simply create an association 1-* t.id to t.parent_id, then create viewLink based on this association.
-
the problem display of hierarchical data on table tree of ADF 11 g
We try to display hierarchical data tree ADF tabletop.
our table a (id, parant_id, name) columns and an open relationship between id and id columns adorning it.
We create module OT, vo and app. Jdev automatically creates connection object and Association.
In the editor view, drag us and drop our table as a tree of ADF table.
In table tree aditor rool we add a rool Association name.
When we launch the application data display incorrectley. For example if the data as
1 aaa 0
2 1 BBB
3 ccc 2
4 2 ddd
We want to display the structure of the tree as
1
-> 2
-> 3
-> 4
but it shows the possibilities of something like (lines "BOLD" incorrectly) added.
1
-> 2
-> 3
-> 4
* 2 *
-> 3
-> 4
* 3 *
* 4 *
(We have 10g. But in the table tree 11g have a different configuration. )
Thank you...I think that if you want to limit the list of records shown at the first level of the tree to those without a father - you'll need create a VO that this query - and then add a viewlink to the full list.
For example by using the employees table in the HR schema, which would be something like a VO with 'where manager_id is null' for the first level, as well as a link from there to the VO used to get other levels. -
Filtering the data names with the prefix donotuse store
Hi all
Currently, we are conducting PowerShell command using the cmdlet Get-data of the below automation tool store. The request is to give the number of logical unit available in the cluster. But we need to edit the script even to retrun lun without donotuse in his name.
New-VIProperty-name availableMB - value-Datastore-ObjectType {$ds = $args [0]; $sum = 0; if ($ds.} ExtensionData.summary.uncommitted - gt 0) {$sum = $ds. ExtensionData.summary.uncommitted}; $sum = $ds. ExtensionData.summary.freeSpace - $sum; $sum = $sum/1024/1024; Return $sum} - Force
(Get-Cluster-name ${vCenterCluster} |) Get - VMhost) | Where-Object {$_.availableMB - ge (${diskSize} * 1024 + ${reservedSpace} * $_.)} CapacityMB) - and $_. CapacityMB - ge (${lunSize} * 1024)- and $_. {Name: like "* _lun *"} | Sort-Object availableMB | Select - 1 first
Please provide your inputs.
For example: If there is one named xxxx_lun01donotuse or donotusexxxx_lun01 we do not want this lun to be returned by the script.
Thanks and greetings
Riyas Hussain has
Far as I can tell you are not feeding datastore objects to the Where clause, so you cannot test on the properties of the data store in the Where clause.
You can feed the objects produced by Get-data store to the Where clause (see my previous answer)
-
ENVY 700-527c: data port availability
ENVY 700-527c, regarding with card mother Kaili2.
This unit had a place available for an additional cd/dvd drive for a total of 2 cd/dvd players.
In addition, there are two bays available for the additional hard drives for a total of 3hdds.
I installed a dvd drive in the extra Bay and I installed a hard drive in one of the two available bays. Everything works well no problems.
I would like to take advantage of the third Bay for an additional hard drive, but there were only two available data ports.
You can see the data ports in the lower right. Currently, all four are busy (2 dvd/cd drives - hard drive 2).
My question is: How can I get a third HDD installed and operational?
Hello
The RED edge connector is a different SATA port. See the image below.
Motherboard taken Kaili2 supported by six SATA 6 devices. Five traditional SATA III ports and an MSATA are available.
Maybe you are looking for
-
Compatibility of Adobe Acrobat and Reader DC
Problems with Adobe Acrobat DC gel/accident. On more than one computer, not one with 10.11.4. In addition, Adobe and MS Office do not seem to play. All Office products, freezing too. Having to manually restart computer.
-
Networking will be faster if I turn on ethernet and wifi?
Is my MacBook Pro (OS x version 10.11.2 (15 c 50) capable of firing party of ethernet and wifi at the same time, to increase network throughput?)
-
2nd question of installation SSD
MSI MS-7525 mother HP Compaq Persario SR5410F-Boston map I checked my BIOS settings to see if I have the opportunity to change SATA to AHCI settings for installing a SSD. Under Settings Advanced SATA ony a 1 option, turn on or off there is no option
-
How to turn the relay for a DT80?
Hello, I am a complete newbie to Labview. I am currently taking data from a DT80, which, from my understanding, is interpreted as a TCP. My question is: is it possible to disable the relay of Labview, via a switch? Even after that performance data
-
Tried and computer > C drive > properties > tools > error without result checking.Backup won't work without a successful checkdisk run!