Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, I believe your question is overcomplicated. </p> <ol> <li>Company has nothing to do with the question</li> <li>DeptTree can simply seen as an extra "parent_dept" in Dept table.</li> <li>Most columns of Dept has nothing to do with the question</li> </ol> <p>So your question can be simplified to:</p> <pre><code>Dept -------- DEPT_CD PARENT_DEPT_CD </code></pre> <p>The biggest problem is: I don't see any recursive function in your original code. And you haven't been clear in telling us what is your expected behavior.</p> <p>If you are simply getting all dept and showing each dept with all the parents of it, you can simply put the dept (with dept code and parent dept code) in a map, using dept code as the key. Then for each dept in the map, recursively shows parent's dept code, and then shows its own code.</p> <p>something like this:</p> <pre><code> //.... for (Dept dept : deptMap.values()) { displayDept(dept, deptMap); } //..... void displayDept(Dept dept, Map&lt;String, Dept&gt; deptMap) { if (dept has parent) { Dept parentDept = deptMap.get(dept.parent); displayDept(parentDept, deptMap); } display dept.code } </code></pre> <p>(Just give you an idea and please write correct code yourself)</p> <p>If you are using Oracle (from the SQL and convention it looks like to me), you may also consider using hierarchical query which can greatly reduce your effort to construct the hierarchy of nodes: <a href="http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm" rel="nofollow">http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload