Re: Query hierarchy to get the parent nodes?
Guys I need a help here please...
I want to ask using any unique value for example in where clause for 'E', I get a lot of 'A' to 'G', which are all related. is there a way to do this?...
IM lookking as
A
B
C
D
E
F
G
When I search for 'E '.
Thanks in advance...
Hello
The design of your table is complicating the problem. If your data is a tree (that is, if each node can have, at most, only one parent) then it would be simpler to have a separate table for each node, if this node has a parent or not. in other words, add a line like
Insert into RELATIONSHIP (PARENT, CHILD) Values (NULL, 'A');
You can create a unique constraint for CHILD.
If you must use the existing design of the table, here's a way to do it:
WITH roots AS
(
SOME parents
IN the relationship
WHERE CONNECT_BY_ISLEAF = 1
START WITH IN '& required' (parent, child)
CONNECT BY child = parent PRIOR
)
SELECT parents as a node
Roots
UNION
SOME children as a node
IN the relationship
START WITH (IN) parent
SOME parents
Roots
)
Parent child = PRIOR CONNECTION
ORDER BY node
;
That's essentially what Blushadow posted and also what Chris suggested, but as the Blushadow request, the request of bottom-up is only encoded only once and the target node (& required in this query) is used only once.
Tags: Database
Similar Questions
-
Get the Parent for each record in the child
Dear Experts,
I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.
Table: relationship
Parent of the child
102 101
103 102
104 103
106 105
107 106
109 108
110 109
Output:
Expected child
102 101
103 102; 101
104 103, 102, 101
106 105
107 106; 105
109 108
110 109
Thank you very much
Hello
MU * 443499 * TR wrote:
Dear Experts,
I have a table that contains the parent and child information. I need to make a request to get the parents of each book of the child table. I tried to write the query but does not get the expected results. Please help me.
Table: relationship
Parent of the child
102 101
103 102
104 103
106 105
107 106
109 108
110 109
Output:
Expected child
102 101
103 102; 101
104 103, 102, 101
106 105
107 106; 105
109 108
110 109
Thank you very much
Why do you want to
Expected child
----- ---------------
110 109
Instead of
Expected child
----- ---------------
110 109; 108
?
You may want something like this:
CONNECT_BY_ROOT SELECT AS children
SYS_CONNECT_BY_PATH (parent, ';') AS expected_output
FROM table_x
WHERE CONNECT_BY_ISLEAF = 1
CONNECT BY child = parent PRIOR
;
If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.
-
Get the parent-child hierarchy of column delimited
I've been on this forum once before, and someone helped me, so I hope I can get help again!
4-15-5987');
Thus, the hierarchy is divided on the hyphen. first parent being 4245, then the next value is-4 (including the hyphen) and what follows is - 1, for example
CREATE TABLE REGEXTEST ( ITEM VARCHAR(20)); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-1'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-10'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-11'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-12'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-13'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-14'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59A7'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59D7'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-4-15-59F7'); INSERT INTO REGEXTEST (ITEM) VALUES ('4245-
I have to be able to bind-1, -4, 4245. Perhaps the simplest is to build a new table with a primary key where it is assigned the id of the parent to the child.
I just can't understand how to divide the individual elements and maintain the hierarchy. As previously mentioned, someone helped me with another part of the problem before where I needed to maintain the entire path of each child with the following query:select nvl(prior item,item) parent, nvl2(prior item,item,null) child from REGEXTEST connect by substr(item,1,instr(item,'-',-1) - 1) = prior item order by child,parent
Now, if I could extrapolate that into a new table:
CREATE TABLE FileHierarchy (ItemID INT NOT NULL PRIMARY KEY, ItemName varchar(50) NOT NULL, ParentID INT NULL);
ItemName is the 4245 or - 4 or - 1 (only) - Yes, including the hyphen.
The ID of the parent-1 would be the ID-4, etc...
Thank you very much in advance!
J.F. Larente
Solution for not having stored the high level:
SQL > select *.
regextest 2
3.POINT LEV
-------------------- ----------
4245 4
4245 4-1
4245 4-10
4245 4-11
4245 4-12
4245 4-13
4245 4-14
4245 4-15
4245 4-15-59 A 7
4245 4-15-59 D 7
4245-4-15-59F711 selected lines.
SQL > with t1 as)
2. Select item
regextest 3
4 Union all the
5 select distinct substr (item, 1, instr(item,'-',1))
6 of regextest
7 ),
8 t2 as)
9. select element,
10 row_number() on id (order by article)
11 from t1
12 )
13. select id,
14 regexp_substr (rtrim (point,'-'), case level when 1 then ' [^-] + $' other '-[^-] + $' end) child.
parentID 15 prior id,
16 regexp_substr (prior rtrim (point,'-'), case level - 1 when 1 then ' [^-] + $' other '-[^-] + $' end) parent
17 of t2
beginning 18 with substr(item,-1) = '-'
19 connect by substr (item, 1, instr(item,'-',-1) - 1) = prior rtrim(item,'-')
20 and article! point prior =
21.ID PARENTID PARENT CHILD
---------- -------------------- ---------- --------------------
1 4245
2 -4 1 4245
3 -1 2 -4
4 -10 2 -4
5 -11 2 -4
6 -12 2 -4
7 -13 2 -4
8 -14 2 -4
9 -15 2 -4
10-59A 7 9-15
11 59 D 7 9 - 15ID PARENTID PARENT CHILD
---------- -------------------- ---------- --------------------
12 59F7 9-1512 selected lines.
SQL >
SY.
-
Need your help to identify the parent nodes
Hello Experts,
I came across a requirement for a company where I get it either parent or child.
In detail:
Each node in the hierarchy was built as branch nodes and I see not all leaf nodes and the target system referencing the Core.Leaf property to determine if it is a parent or child, now, I have to change the process so that
If the node does not have children even though he is a member, then the property should give as the child of another parent.
Please help me with this requirement.
Please let me know if you need other details as well, as I am now learning DRM so there may be some gorgonians in my language
There is a function called IsBottomNode(), you can take advantage of this feature to your needs.
If (IsBottomNode (ABBREV (()), Child, parent)
-
How to write a hierarchical query so that only the child nodes are displayed?
Hi all
I have a hierarchical query that I use in an area of tree demand APEX and there are nodes that have no children and I am trying to find a way to not display these nodes. Essentially if the user does not have to develop a lot of knots to know that nothing exists at the most detailed level.
The data are based on the Oracle Fusion FND tables but for example purposes here is enough data to illustrate my question:
create table APPL_TAXONOMY_HIERARCHY (SOURCE_MODULE_ID varchar2(30), TARGET_MODULE_ID varchar2(30)); create table APPL_TAXONOMY_TL (module_id varchar2(30), description varchar2(100), user_module_name varchar2(30), language varchar2(5)); create table APPL_TAXONOMY (MODULE_ID varchar2(30), MODULE_NAME varchar2(30), MODULE_TYPE varchar2(10), MODULE_KEY varchar2(30)); create table TABLES (table_name varchar2(30), module_key varchar2(30));
insert into APPL_TAXONOMY_TL values ('1', null, 'Oracle Fusion', 'US' ); insert into APPL_TAXONOMY_TL values ('2', null, 'Financials', 'US' ); insert into APPL_TAXONOMY_TL values ('3', null, 'Human Resources', 'US' ); insert into APPL_TAXONOMY_TL values ('20', null, 'Accounts Payable', 'US' ); insert into APPL_TAXONOMY_TL values ('10', null, 'General Ledger', 'US' ); insert into APPL_TAXONOMY_HIERARCHY values ('1', 'DDDDDDDD'); insert into APPL_TAXONOMY_HIERARCHY values ('2', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('3', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('4', '1'); insert into APPL_TAXONOMY_HIERARCHY values ('10', '2'); insert into APPL_TAXONOMY_HIERARCHY values ('20', '2'); insert into APPL_TAXONOMY values ('1', 'Fusion', 'PROD', 'Fusion'); insert into APPL_TAXONOMY values ('2', 'Financials', 'FAMILY', 'FIN'); insert into APPL_TAXONOMY values ('10', 'GL', 'APP', 'GL'); insert into APPL_TAXONOMY values ('3', 'Human Resources', 'FAMILY', 'HR'); insert into APPL_TAXONOMY values ('20', 'AP', 'APP', 'AP'); insert into tables values ('GL_JE_SOURCES_TL','GL'); insert into tables values ('GL_JE_CATEGORIES','GL');
My hierarchical query is as follows:
with MODULES as ( SELECT h.source_module_id, b.user_module_name, h.target_module_id FROM APPL_TAXONOMY_HIERARCHY H, APPL_TAXONOMY_TL B, APPL_TAXONOMY VL where H.source_module_id = b.module_id and b.module_id = vl.module_id and vl.module_type not in ('PAGE', 'LBA') UNION ALL select distinct table_name, table_name, regexp_substr(table_name,'[^_]+',1,1) from TABLES --needed as a link between TABLES and APPL_TAXONOMY union all select module_key as source_module_id, module_name as user_module_name, module_id as target_module_id from appl_taxonomy VL where VL.module_type = 'APP') SELECT case when connect_by_isleaf = 1 then 0 when level = 1 then 1 else -1 end as status, LEVEL, user_module_name as title, null as icon, ltrim(user_module_name, ' ') as value, null as tooltip, null as link FROM MODULES START WITH source_module_id = '1' CONNECT BY PRIOR source_module_id = target_module_id ORDER SIBLINGS BY user_module_name;
In Oracle APEX, this gives a tree with the appropriate data, you can see here:
https://Apex.Oracle.com/pls/Apex/f?p=32581:29 (username: guest, pw: app_1000);
The SQL of the query results are:
STATUS TITLE LEVEL VALUE ---------- ---------- ------------------------------ ------------------------------
1 1 oracle Fusion Oracle Fusion -1 2 financial tables Financials -1 3 accounts payable Accounts payable 0 4 AP AP -1 General Accounting 3 General Accounting -1 4 GL GL 0 5 GL_JE_CATEGORIES GL_JE_CATEGORIES 0 5 GL_JE_SOURCES_TL GL_JE_SOURCES_TL 0 2 human resources Human resources The lowest level is the name of the table to level 5. HR is not any level under level 2, in the same way, "AP" (level 4) has nothing below, i.e. no level 5 and that's why I don't want to show these nodes. Is this possible with the above query?
Thanks in advance for your suggestions!
John
Hello
The following query will include only the nodes of level = 5 and their ancestors (or descendants):
WITH modules LIKE
(
SELECT h.source_module_id
b.user_module_name AS the title
h.target_module_id
To appl_taxonomy_hierarchy:
appl_taxonomy_tl b
appl_taxonomy vl
WHERE h.source_module_id = b.module_id
AND b.module_id = vl.module_id
AND vl.module_type NOT IN ('PAGE', "LBA")
UNION ALL
SELECT DISTINCT
table-name
table_name
, REGEXP_SUBSTR (table_name, ' [^ _] +')
From the tables - required as a link between the TABLES and APPL_TAXONOMY
UNION ALL
SELECT module_key AS source_module_id
AS user_module_name module_name
module_id AS target_module_id
Of appl_taxonomy vl
WHERE vl.module_type = 'APP '.
)
connect_by_results AS
(
SELECT THE CHECK BOX
WHEN CONNECT_BY_ISLEAF = 1 THEN 0
WHEN LEVEL = 1 THEN 1
OF ANOTHER-1
The END as status
LEVEL AS lvl
title
-, NULL AS icon
, LTRIM (title, "") AS the value
-, NULL as ToolTip
-, Link AS NULL
source_module_id
SYS_CONNECT_BY_PATH (source_module_id - or something unique
, ' ~' - or anything else that may occur in the unique key
) || ' ~' AS the path
ROWNUM AS sort_key
Modules
START WITH source_module_id = '1'
CONNECT BY PRIOR Source_module_id = target_module_id
Brothers and SŒURS of ORDER BY title
)
SELECT the status, lvl, title, value
-, icon, tooltip, link
OF connect_by_results m
WHEN THERE IS)
SELECT 1
OF connect_by_results
WHERE the lvl = 5
AND the path AS ' % ~' | m.source_module_id
|| '~%'
)
ORDER BY sort_key
;
You may notice that subqueries modules and the connect_by_results are essentially what you've posted originally. What was the main request is now called connect_by_results, and it has a couple of additional columns that are necessary in the new main request or the EXISTS subquery.
However, I am suspicious of the 'magic number' 5. Could you have a situation where the sheets you are interested in can be a different levels (for example, some level = 5 and then some, into another branch of the tree, at the LEVEL = 6, or 7 or 4)? If so, post an example. You have need of a Query of Yo-Yo, where you do a bottom-up CONNECT BY query to get the universe of interest, and then make a descendant CONNECT BY query on this set of results.
-
Get the parent (paragraph) of the text
Hi all
I met a problem and can't seem to find the solution myself. It's like this:
Let's say you have a story with two paragraphs. A paragraph has 'Hello' in it and the other a 'world' in as text.
You can select e.g. 'Hello', then click on a button, and then after clicking on the button change for example "Hello".
So you have a paragraph with "Greetings" and the other with the "world".
Now, I have the following code I need to change:
selectedContent var = app.selection [0] .silence; It's selection, "Hello".
var contentToChange = app.selection [0] .parent; This is the story.
I want to contentToChange be the paragraph in the text.
.parent Gets the story, so everything disappears and becomes just "Hello".
Tried a lot of things, but impossible to find the solution (what should I use instead of 'parent' to get the paragraph).
Can anyone help please, thank you in advance
Greetings
contentToChange = app.selection [0] .paragraphs [0]
is what you are looking for
-
How to remove the Parent node in the tree
Hello
I have a component of the tree in oracle adf and I want to delete a node in this tree. When I want to remove a child node, I don't have an error but when I want to delete a parent node, who have children, I have error. because it has foreign keys.
Can someone help me?
You can follow one of two approaches suggested by Timo
I'd rather cascase remove option - see this https://www.silnium.com/blog/adf/implementing-adf-cascade-delete/
Cascade Delete - ADF | Technology blog
If you want to cross-see this
-
using the MovieClipLoader, everything works fine.
fixation of a series of clips with a nested element and loading a jpg in each clip nested these MovieClip.
in the func onLoadInit listener, I passed the name of the element that is responsible, how carefully I reference the parent of this element?
Currently I can get the name nested mc (I just use target_mc as the use of help files), but you need to refer to its parent.
THX!Have you tried target_mc._parent
-
How can I get the parental control?
I want to set up parental controls, but when I go into my control panel find the sound icon is not there and I went looking and looking but nothing came.
Windows XP is not the Parental control. This feature has been added in Windows Vista.
XP can use Internet Explorer Content Advisor and allows to control the time that users can connect to.
-
Query help - to get the number of employees joined on each month regardless of the year
Hi all
I wrote the code below for number of employees joined each month regardless of the year of the employee table. But I couldn't get the result. Kindly help me where I'm wrong in my code,
Select to_char (hiredate, 'my') as join, count (empno) under the number
WCP
To_char Group (hiredate, 'my')
After having count (empno) > 1;
Your application displays the list of months (regardless of the year) where more than one employee was engaged with number of emplyees hired this month here. If you want months even if nobody was hired months thast, you emp table outer join to the list of every month:
with t as)
Select the level m
of the double
connect by level<=>=>
)
Select to_char (to_date (TM, 'mm'), 'my') Lun,
Count (e.empno) cnt
t
left join
E EMP
on Tahina = to_char (e.hiredate, 'mm')
Group of Tahina
order of Tahina
/
MY CNT
--- ----------
1 jan
February 2
Mar 0
Apr 2
May 2
1 Jun
July 0
August 0
2 sep
Oct 0
1 novMY CNT
--- ----------
Dec 312 selected lines.
SQL >
SY.
-
Table tree - Select All child nodes at the same time when the Parent node is selected.
Hi all
I am relatively new to ADF and JDeveloper, and so I hit a problem I can't deny.
I have a tree table that looks like the following...
1 status | Name | Employee ID
-> Status 2. Name | Employee ID | etc. | etc.
-> 3 status. Name | Employee ID | etc. | etc. | etc.
I want to do is when I select the node from top of the line/parent (line 1) page I would like child nodes (lines 2 and 3) to choose from in the same mouse clicks.
In the end I will be citing a listener of the property on a button, once the selection was made, to change the value of the 'Status' column in all three levels that have been selected.
NB. each level in the tree above is derived from 3 views distinct, who are joined on the employee ID.
Thanks in advance for your help and your advice.
Kind regards
Jamie.
Jamie, tell us your version of jdev, please!
This http://andrejusb.blogspot.de/2012/11/check-box-support-in-adf-tree-table.html Blog shows how to implement this.
Timo
-
Why the VI begins to break when I get the property nodes?
Hello
I am an engineering student and have to do a job in labview. It is a Signal Generator with osciloscope integrated.
The VI worked fine ultil I add nodes property to change wavegraph scales and the departure of VI breaking with them.
Can anyone see my VI and tell me why is it?
I send the VI below.
Best regards
Ricardo Ferreira
The VI is not broken and can work.
However, your axes are defined auto-scaling so that nodes of property for the axes and auto-scaling are constantly fighting among themselves.
-
How can I change this query? to get the results I want
This query
Returnsselect SHRTGPA_pidm, SZSTCLA_TERM_CODE, SHRTGPA_GPA_HOURS from szstcla,SHRTGPA where szstcla_pidm = 74246 and SHRTGPA_pidm = szstcla_pidm and SZSTCLA_TERM_CODE <> SZSTCLA_TERM_CODE_MATRIC and SHRTGPA_TERM_CODE = SZSTCLA_TERM_CODE
I want to group the query will return74246 201020 4 74246 201120 4 74246 201110 4 74246 201210 4 74246 201220 4
201220 2074246 201020 4 74246 201120 8 74246 201110 12 74246 201210 16
Two copies
Published by: Frank Kulash, November 8, 2012 11:32
-
Get the parent in the child VO inst value
I have a master detail on the page and in a column of vo child I want to display the current line of a master vo.
Then, how to refer to the master vo-current rank in the child attribute in line on UI? in the same fields vo can be accessed as #{rank. AttrbiuteName.inputValue}Maybe this can help: http://www.gebs.ro/blog/oracle/adf-bc-viewlink-viewlinkaccessor-and-groovy/
or you can bind the value property in the retail method column in managed bean that can extract value iterator parent, something like this:public String getSomeFieldFromParent(){ return (String)ADFUtils.findIterator("parentIterator").getCurrentRow().getAttribute("SomeAttribute"); }
Dario
-
How to get the first node in a XMLList have thong.
Hello, I have this XMLList:
< content >
< TextFlow color = "#000000' columnCount '2' = >
< p > < /p > one
< / TextFlow >
< / content >I need to get < textFlow > as a XMLList and String.
then iterate over the XML (e.target.data). TextFlow table.
Maybe you are looking for
-
Magic Mouse 2 scrolling does not
I have a magic mouse 2 I have installed on my Windows laptop, 10 but I can't get the scrolling to work, I know there is a way to make it work, but I can't seem to get the mining work like everyone else. I really want to buy a different mouse. Can s
-
Folder for deleted files is called 'Trash' on another PC, it is named 'Deleted' - why?
Identical copies of Thunderbird 24.4.0 on two PC but deleted folder a different name: one is "deleted", the other is "Trash".
-
Mavericks of hp photosmart b110
I'm sure you can help. I try to get my Photosmart B110a connected wireless to my Macbook Pro in Mavericks 10.9.2 The printer is connected is the network that I can connect via my browser using IP inside address and I see everything about the printer
-
OfficeJet Pro L7650: Disables the settlement L7650 screen saver in win 10
When I install the drivers for Office Jet Pro L7650 screen saver stops working. I tried to change the settings on the PC nothing works. When I remove the PC screen saver L7650 stand works correctly. Reinstall the printer turns off the screen saver
-
hardware video capture... my web cam worked fine utill today.
From today I can not get my web cam to work. I deleted and reloaded but didn't achieve the same result "no video capture hardware" how to fix this? the program loads ok, but the message no video capture always happens... can someone give advice... Th