473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Counting Parent Child Level

We are using the following to retrieve parent child:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Cursor get_child_org is
  3. SELECT distinct
  4.        o.ORG_ORGANIZATION_ID org_id,
  5.        o.name belongs_to,
  6.        uic.code org_uic,
  7.        SYS_CONNECT_BY_PATH(o.name, ' - ') "ORG_STRUCTURE"
  8. FROM   ORG_ORGANIZATIONS o,
  9.        org_uic uic
  10. WHERE  o.org_organization_id = uic.org_organization_id(+)
  11. START WITH o.org_organization_id = vParent_id
  12. CONNECT BY PRIOR o.org_organization_id = o.owner_organization_id
  13. Order By ORG_STRUCTURE
  14. ;
  15.  
Is there a method to count the parent child level? I would like to return a count to indicate the level versus the parent child path by appending hyphens '-'.
Nov 17 '08 #1
2 3613
amitpatel66
2,367 Expert 2GB
And what is the output that you are getting for your query? Yes CONNECT BY PRIOR is the concept of getting hierarchical data.
Nov 18 '08 #2
Pilgrim333
127 100+
Hi,

As you are adding ' - ' between each node, I found you a simple way of getting the level. Each time you add ' - ' this means you are adding another level. So you need a way to count these additions. You could write a function that counts the number of occurances of a character in a string. On the other hand, a much faster way would be adding the following line to your select clause:

Expand|Select|Wrap|Line Numbers
  1.  length(SYS_CONNECT_BY_PATH(o.name, ' -')) - length(SYS_CONNECT_BY_PATH(o.name, '-')) "level"
The first sys_connect_by adds 2 chars to the complete path for each child, the second one adds just one char to the complete path for each child. Subtract the length of these two and you have the number of levels. It counts the parent as one, so if you only have the parent, then the result is one. If you don't want to count the parent, then just substract 1 from to result.

I hope this will help you out, let us know if it does or not. If it doesn't then we'll look for some other solution.

Pilgrim.
Nov 18 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Steven | last post by:
Hi there, I have an admin system (Add/Modify/Delete) for two types of records in the database. They have a Parent - Child relationship My problem is that I want to display on the "parent"...
3
by: maricel | last post by:
Is there a way to list (using db2 command or catalogs) to list hierarchy of table parent & child relationship: 1) A list that shows which table should be deleted first,second,third... 2) A list...
25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
13
by: Stuart McGraw | last post by:
I haven't been able to figure this out and would appreciate some help... I have two tables, both with autonumber primary keys, and linked in a conventional master-child relationship. I've...
5
by: Patrick Vanden Driessche | last post by:
Hi All, I'm currently writing an in-house Form validation framework (WinForms) which is based on 'Component'-inheriting object. So basically, I have a small hierarchy. FormValidator +--...
16
by: John | last post by:
Hi I have posted this question several times but have received no reply. I have a main form which contains a panel which in turn contains a child form, like this; MainForm->MyPanel->ChildForm....
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
6
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.