Get child nodes and only child nodes from a tree?

Hi all,
Relatively simple table
create table replaced_parts
old_part_number varchar(7),
replaced_part_number varchar(7),
updated_date date
insert into Replaced_parts values('AAAAA/1', 'BBBBB/1', '2012-Feb-16');
insert into Replaced_parts values('BBBBB/1', 'FFFFF/1', '2012-Feb-23');
insert into Replaced_parts values('YYYYY/3', 'ZZZZZ/3', '2012-Mar-17');
insert into Replaced_parts values('FFFFF/1', 'LLLLL/1', '2012-Mar-18');
insert into Replaced_parts values('LLLLL/1', 'HHHHH/1', '2012-Mar-19');The question is how do I issue a select using 'AAAAA/1' and get the result 'HHHHH/1'
i.e. (A... -> B, B->F, F->L, L->H)
and select using 'YYYYY/3' to get 'ZZZZZ/3' (Y... ->Z)?
It would be really nice if I could also get my original value, say, 'CCCCC/1' if there is no entry
for 'CCCCC/1' in the replaced_parts table (maybe NVL?).
I have googled and tried various combinations of CONNECT BY, PRIOR, ISLEAF... &c. but
am beating my head off a brick wall at the moment.
TIA,
Paul...

>
Hi, Paul,Hi again Frank - couldn't sleep and am back at the "£$%^&* computer...
Yeah - it's a pity they weren't correct - I'll make doubly sure in future - see
my edited post (with DROP TABLE commands inter alia - I also removed
Order_Parts.User_Number since it was redundant - all that's needed is
Order_Number (normalisation) so now your SQL doesn't work - sorry
about that.
Just saying something "doesn't work" isn;t very helpful. What exactly is wrong with the SQL
statements I posted? Point out a couple of places where they are wrong, and explain how
you get the right results in those places.Nothing is wrong with your SQL - I meant *sorry* about the confusion in the DDL/DML from my end.
Now, I'm sorry again about the ambiguity of my English.
I'll reconstruct the original data that I gave you and re-run your SQL against that data - again,
this is *totally* my fault.
My tables creation script seems to work fine now - I've edited my reponse to Solomon - the definitive scripts
are now there - with Order_Parts.User_Number gone and the TO_DATE(...) as
you suggested - the VARCHARs seemed to give the right result though - but I
agree that if there's a correct way of doing it, then it should be done that way.
Remember why you need to go to the trouble of posting CREATE TABLE and INSERT statements
for some sample data here. It's to allow the people who want to help you to re-create the prolem
and test their ideas. I know, and that's why I did it - the OR REPLACE that I added (stupidly and without thinking or testing) was
so that people wouldn't have to go to the trouble of dropping the tables - I have now added
DROP TABLE blah... to the beginning of the script so it won't be necessary.
I have over 600 posts on this forum and only 26 questions - most of my time
spent here is trying to help (to the best of my limited ability - I'm not a guru
like yourself) and learning - it's amazing the number of times problems that
I've seen here have subsequently arisen at work - and I am frequently
frustrated by some posters' inability to explain their problem or at least give test
cases.
I can forgive bad English (except my own) - not everybody is a fluent speaker of the language,
but SQL should run no matter what language one speaks.
I appreciate that people are volunteering their time and effort here and I really do
try and make it as easy as possible for them when I ask questions - I messed up
this time, I'm afraid. It might also be the fact that I'm moving between SQL*Plus
and SQL Developer and a text editor that I got confused (plus, fatigue didn't help...)
In general, other people are not going to test anything on your system. I'm going to test
things on my system, Solomon will test things on his system, and other people will test things
on other systems. Well, if ever you're in Dublin ;). Again, I appreciate the effort that you, Solomon and sKr have
gone to in helping me.
Your INSERT earlier statements did not work on my system, because you were using a VARCHAR2
in a place where a DATE was required. The correct thing to do is to use DATEs where DATEs are required. Indeed, and I agreed with you that if there's a right way of doing it, then it should be done that way.
If your NLS settings are such that this is not causing you any errors right now, it's still a good
idea for you to fix it; but, at any rate, whether it works on your system isn't what's important in
this case; you're posting it to run on other peoples' systems.Ahhh.... <the blinding light of a moment of epiphany descends on Paul> I didn't realise it was
an NLS setting - of course Americans will be different - it's just that I thought that YYYY-Mon-DD
worked everywhere (I tried to avoid the day-first/month-first pitfall ) but now that you've explained
it to me, I'll *never* make that mistake again.
Yes - my mistake - I've now corrected the error
Where are the desired results? Don't merely hide them in an old message; post them in a new message.OK. I'll put it in a reply to this post. I really am endeavouring to be as clear as possible - please
excuse my errors - I will do better in future. I'm also very annoyed at my own incompetence and at
having put you to more trouble than you would have had to go to if I had my wits about me.
- should I keep Order_Parts.User_Number even
if it isn't conformant to normalisation rules?
If you have a good reason, it's okay to store de-normalized data. For example, some address tables in
the US contain both state and ZIP code, even though state is fucntionally depenedent on ZIP code. I think that in this case, denormalisation is not called for.
Re. the ZIP code thing, yeah, sure AIUI, the first two digits are dependent on the state, but the
last three? They're more or less random - at least in the sense that there's no way to type
in an address and calculate (mathematically, using a formula) them - so unless one were
to have weird SQL lookups to a "State" table for the first two digits and then take the final
three from a user-entered string field, then do a TO_CHAR on the returned 2-digit state number and add
this to the 3-character one - I can't see how the ZIP code is an example of this? But, maybe
(unless you wish to discuss that) we're getting side-tracked. Perhaps I'll ask this question
on comp.databases.theory?
Oracle actually added a new feature in version 11 (virtual columns) to make de-normalizing easier.Hmmm... is adding virtual columns denormalisation per se? My favourite "cheap'n'cheerful"
db server (Firebird) has had a COMPUTED BY clause (same idea) for yonks (> 12yrs) - no data
is actually stored - rather it is calculated on the fly. Another one for comp.databases.theory
perhaps?
BTW, wouldn't triggers remove all this hassle? It was my first idea, but trying to do it
purely through SQL is now *obsessing* me ;)
That would be another example of de-normalization. If the benefits of doing that outweigh the
costs, then go ahead. A trigger will take some effort to maintain, and it will make all DML slower, regardless
of how often that derived value is needed. Having the extra column will make some queries simpler and faster. Disk is cheap. Have an Original_Orders table (never changes) and a Revised_Orders table. When
a part replacement occurs - for orders that haven't been fulfilled (boolean flag?), change the
old part number to the new one. I can't imagine that replacement occurs very frequently, so
the expense of a trigger would IMHO be minimal - plus the down side of any trigger would
be mitigated by greatly simplifying the production of the Revised_Orders report?
... I'll experiment with what you've given me so far - but it's 23:40 here now, so I won't
get a chance to do it tonight - unfortunately, I *do* have to sleep.
If you haven't tested it yet, why did you start this message saying "your SQL doesn't work"?Sorry - what I meant was it obviously doesn't work when this eejit (i.e. me) has changed
the table structure - I did run it quickly (your 1st statement) against the (revised table
structure, the one you hadn't seen and I don't think even a man of your great SQL talents
can be expected to write working queries against unknown table structures :)).
Again, thanks for your help so far - I'll post the *_correct_* DDL and DML as a reply to this post
with the desired result. I'll also reconstitute the old (i.e. the one you worked against) tables
and data and let you know - again as a reply to this post - if I can at least learn something
from my fiasco, it won't have been a total waste of my time, and again, apologies for
wasting yours.
Thanks again and rgs.
Paul...
Edited by: Paulie on 22-Mar-2012 02:50

Similar Messages

  • Can't remove a node from a tree

    I am using the custom tree dataDescriptor provided in Flex live
    doc. It works for creating the tree and add notes, however when I
    try to remove a node from the tree it cant work. Does anyone have
    any idea?
    This is the code for MyCustomeTreeDataDescriptor.as
    package
    import mx.collections.ArrayCollection;
    import mx.collections.CursorBookmark;
    import mx.collections.ICollectionView;
    import mx.collections.IViewCursor;
    import mx.events.CollectionEvent;
    import mx.events.CollectionEventKind;
    import mx.controls.treeClasses.*;
    public class MyCustomTreeDataDescriptor implements
    ITreeDataDescriptor
    // The getChildren method requires the node to be an Object
    // with a children field.
    // If the field contains an ArrayCollection, it returns the
    field
    // Otherwise, it wraps the field in an ArrayCollection.
    public function getChildren(node:Object,
    model:Object=null):ICollectionView
    try
    if (node is Object) {
    if(node.children is ArrayCollection){
    return node.children;
    }else{
    return new ArrayCollection(node.children);
    catch (e:Error) {
    trace("[Descriptor] exception checking for getChildren");
    return null;
    // The isBranch method simply returns true if the node is an
    // Object with a children field.
    // It does not support empty branches, but does support null
    children
    // fields.
    public function isBranch(node:Object,
    model:Object=null):Boolean {
    try {
    if (node is Object) {
    if (node.children != null) {
    return true;
    catch (e:Error) {
    trace("[Descriptor] exception checking for isBranch");
    return false;
    // The hasChildren method Returns true if the node actually
    has children.
    public function hasChildren(node:Object,
    model:Object=null):Boolean {
    if (node == null)
    return false;
    var children:ICollectionView = getChildren(node, model);
    try {
    if (children.length > 0)
    return true;
    catch (e:Error) {
    return false;
    // The getData method simply returns the node as an Object.
    public function getData(node:Object,
    model:Object=null):Object {
    try {
    return node;
    catch (e:Error) {
    return null;
    // The addChildAt method does the following:
    // If the parent parameter is null or undefined, inserts
    // the child parameter as the first child of the model
    parameter.
    // If the parent parameter is an Object and has a children
    field,
    // adds the child parameter to it at the index parameter
    location.
    // It does not add a child to a terminal node if it does not
    have
    // a children field.
    public function addChildAt(parent:Object, child:Object,
    index:int,
    model:Object=null):Boolean {
    var event:CollectionEvent = new
    CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
    event.kind = CollectionEventKind.ADD;
    event.items = [child];
    event.location = index;
    if (!parent) {
    var iterator:IViewCursor = model.createCursor();
    iterator.seek(CursorBookmark.FIRST, index);
    iterator.insert(child);
    else if (parent is Object) {
    if (parent.children != null) {
    if(parent.children is ArrayCollection) {
    parent.children.addItemAt(child, index);
    if (model){
    model.dispatchEvent(event);
    model.itemUpdated(parent);
    return true;
    else {
    parent.children.splice(index, 0, child);
    if (model)
    model.dispatchEvent(event);
    return true;
    return false;
    // The removeChildAt method does the following:
    // If the parent parameter is null or undefined, removes
    // the child at the specified index in the model.
    // If the parent parameter is an Object and has a children
    field,
    // removes the child at the index parameter location in the
    parent.
    public function removeChildAt(parent:Object, child:Object,
    index:int, model:Object=null):Boolean
    var event:CollectionEvent = new
    CollectionEvent(CollectionEvent.COLLECTION_CHANGE);
    event.kind = CollectionEventKind.REMOVE;
    event.items = [child];
    event.location = index;
    //handle top level where there is no parent
    if (!parent)
    var iterator:IViewCursor = model.createCursor();
    iterator.seek(CursorBookmark.FIRST, index);
    iterator.remove();
    if (model)
    model.dispatchEvent(event);
    return true;
    else if (parent is Object)
    if (parent.children != undefined)
    parent.children.splice(index, 1);
    if (model)
    model.dispatchEvent(event);
    return true;
    return false;
    This is my tree definition:
    <mx:Tree width="143" top="0" bottom="0" left="0"
    height="100%"
    id="publicCaseTree"
    dataDescriptor="{new MyCustomTreeDataDescriptor()}"
    dataProvider="{ac}"
    defaultLeafIcon="@Embed('assets/caseIcon.png')"
    change="publicTreeChanged(event)"
    dragEnabled="true"
    dragMoveEnabled="false"/>
    This is how I remove the selected node from the tree. When
    Delete button is clicked, the doDeleteCase function is
    exectuted.
    public function publicTreeChanged(event:Event):void {
    selectedNode =
    publicCaseTree.dataDescriptor.getData(Tree(event.target).selectedItem,
    ac);
    public function doDeleteCase(event:Event):void{
    publicCaseTree.dataDescriptor.removeChildAt(publicCaseTree.firstVisibleItem,
    selectedNode, 0, ac);
    Any help would be appreciated.Thanks.

    Finally I removed nodes from tree, but not sure I did in the
    right way. Anybody encounter the same problem, please
    discuss.

  • Copy node from XML tree problem

    I am trying to copy an XML node 9whic hmay have child nodes) from one tree to another with the code
    nodes = dataDoc.getElementsByTagName("text");
                   currentElement = (Element) nodes.item(0);
                   textNode.appendChild(nodes.item(0).cloneNode(true));
    gives the error
    org.apache.crimson.tree.DomEx: WRONG_DOCUMENT_ERR: That node doesn't belong in this document.
         at org.apache.crimson.tree.ParentNode.checkDocument(ParentNode.java:250)
         at org.apache.crimson.tree.ParentNode.appendChild(ParentNode.java:333)
    What am I doing wrong?
    Regards,
    MArk

    What am I doing wrong?Failing to use the Document.importNode() method.

  • How to get record created and modified user name from SharePoint Database?

    Hi,
    My SharePoint Portal is in Window Authentication. Some users have added requests to Lists. I want to find user name of the Created By and Modified By.
    Only ID is available in the corresponding columns in Content Database table. In which table the users details would store in Content Database.
    Thanks & Regards
    Poomani Sankaran

    hi, you can find the user details inside UserInfo Table in content database. But i would suggest not to directly query the content databse not even for select as it will affect the indexes.
    why not follow the link
    http://www.sharepoint4arabs.com/AymanElHattab/Lists/Posts/Post.aspx?ID=99
    also if you just need the basic created by and modified by info than use SharePoint Object Model To get these values using ECMA script use below link
    http://www.c-sharpcorner.com/UploadFile/anavijai/get-created-by-and-modified-by-values-from-sharepoint-2010-l/ using Client side object model https://msdn.microsoft.com/en-us/library/office/ee534956%28v=office.14%29.aspx?f=255&MSPPError=-2147217396
    Using server Side Object model
    http://www.sharepointcto.com/View.aspx?id=15
    Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer

  • 3750x Stack UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree

    A Cisco Stack 3750X switch report the following error message:
    %UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree.
    every minute +-20 sec
    Cisco IOS Software, C3750E Software (C3750E-IPBASEK9-M), Version 15.0(2)SE4, RELEASE SOFTWARE (fc1)
    analog bug: https://tools.cisco.com/bugsearch/bug/CSCsz93221

    WS-C3750G-24PS-E C3750-IPBASEK9-M version 12.2(53)SE2
    After implementing 802.1x with Avaya IP phones
    %UTIL-3-TREE: Data structure error--attempt to remove an unthreaded node from a tree
    Port then fails authentication and goes into vl-err-dis

  • After upgrading iOS5, my apps were deleted. Truing get them back, and only partially, the other apps, apple store is changing me again. Tried to restore and and sent an error. Now the Ipad won´t even boot. Can anyone help, besides Apple?

    The iOS5 erased all my apps. Went to get them back and only part of it was recognized by Apple store. The others the store prompts to pay. I tried to go back to the old system and restore but as it was in sync an error ocurred and now I don´t have even the operating system. It won´t rebbot. I am afraid it will not stop searching the booting system until batery is dead and it will take many hours.
    Any chance somenone ran into the same problem that could help?

    The only people who can possibly assist you with this is Apple Customer Relations, call your local Apple contact number and ask for Customer Relations then explain your situation clearly and politely (be firm but don't rant).
    You might want to investiage what the local laws are regarding defective goods and 'fit for use' definitions on warranties etc. Consumer Protection can be a useful tool to use or bargain with if needed ...

  • I am running OS10.6.8 and have a mail box duplication. I use gmail and when I open my mail I have both the Apple Mail and another set of boxes for Gmail. Both get all mail and when I delete from one, it deletes from the other. How can I get rid of the dup

    I am running OS10.6.8 and have a mail box duplication. I use gmail and when I open my mail I have both the Apple Mail and another set of boxes for Gmail. Both get all mail and when I delete from one, it deletes from the other. How can I get rid of the dup

    Hi,
    According to your descriptioin, I don't think this is system problem, it should be Intel driver problem. It would be contact Intel to confirm this issue whether this is their driver problem.
    Roger Lu
    TechNet Community Support

  • HT201269 My Iphone 4 is water damaged and won't work at all so I've bought a new Iphone 5c - can I get my messages and whats app chats from my old to my new phone - they have different sized sims?

    My Iphone 4 is water damaged and won't work at all so I've bought a new Iphone 5c - can I get my messages and whats app chats from my old to my new phone - they have different sized sims?

    There is nothing saved on the SIm card in an iphone.  If you have a backup of the old phone restore that to the new phone

  • Cant get current node from TreeCellEditor isCellEditable().

    I have a custom TreeCellEditor but I do not want to allow the user to edit the root node.
    I was hoping to use isCellEditable() but I can not seem to get the node that is being edited from the EventObject.
    I can get the JTree, (from event.getSource(), but there is no way to get the node that is being tested. I have tried using:
    tree.getEditingPath()
    tree.getLastPathComponent()
    tree.getSelectionPath()But they all return null at the time isCellEditable() is called.
    Does anyone know of a way to get the node that is being tested?
    Thanks,
    Jerome.

    well, that method is meant to be generic such that it decides if editing is possible for the type of event.
    JTable has a separate isCellEditable method, but so does TableModel, so typically, you have a custom table model that implements the method there to return, and in that you know what cell.
    For JTree, I don't know why there's no similar method in the TreeModel interface. There is in JTree, but I really think that should be a function of the model, not the view.
    For JTable, I believe it's only there as a pass-thru, calling the table model's method underneath to get the value.

  • How do I get Photo Stream to only import photos from my phone and not push photos to my phone.

    Hi
    Just purchased an Imac (first time mac user) and imported all my photos from my PC.  I have been using photo stream on my phone and ipad and like it.  The problem is, as far as I can tell, that I have added thousands of photos to the Imac and it now consider those to be new additions.  It is sharing those photos to my phone and Ipad and filling both up very quickly.  Is there a way that I can only stream photos from the phone to Iphoto on my imac and not from the imac to the phone?  I realize that in 30 days, this should correct itself, but for the time being it is a huge hassle.  Im sure there is some setting in iphoto that will alleviate my problem

    If you have a mac....
    launch iPhoto
    click the word "iPhoto" beside the apple, and select "preferences / photo stream"
    what synces, is listed here
    uncheck what you desire, and simply close iPhoto.  It will save the changes
    Also......
    Click the apple / system prefences / iCloud - if you wish to stop "photo stream" completely, you can uncheck it here.
    Photo Stream FAQ - http://support.apple.com/kb/HT4486.

  • Deleting Nodes from XML Tree (JTree)

    I have created a XML Tree(extended from JTree) using XNodes ( extended from DefaultMutableTreeNode)
    After some insertions, i need to delete certain nodes from the XML Tree.. but after deletion, XNode will be null.
    subroutine is as follows...
    appreciates any advice
    Thanx
    private XNode RemoveExtraNode( XNode xNode ){
    int child;
    String nodeType;
    XNode childNode=null;
    if ( (child=xNode.getChildCount() ) > 0){
    for(int i=0;i<child;i++){
    childNode=(XNode)xNode.getChildAt(i);          
         nodeType = childNode.getType();
         if(nodeType.equals("DTD") )
         childNode.removeFromParent();
    }//end for (int i=1;i<child;i++)
    }//endif((child=xNode.getChildCount())!=0)
    return xNode;     
    }//RemoveExtraNode

    Hi IKEDA
    Thanx for the reply.
    I have tried xNode.remove(childNode) b4 and it still return a null JTree.
    Anyway fyi i discover i can delete last child of xNode and return the correct java tree. therefore to delete a node of my choice i simply insert its next sibling nodes in its place and delete that particular node when it becomes the last child.

  • If I change my Apple ID, can I get my iTune and App purchases transferred from the old to the new ID?

    I have a child who is now of age to create an Apple ID.  If I create a new Apple ID, can I tranfer the iTune and App Store purchases from my existing Apple ID to the new one for my child?

    No, it's not currently possible to transfer content from one account to another account - all items remain tied to the account that originally bought/downloaded them, so they will remain tied to your account.
    As long as your account is authorised on the computer's iTunes that he/she syncs to, and those items are in its library, then he/she should be able to continue to have them on their device (though only your account will be able to download updates to those apps)

  • Windows 8.1 HP AMD laptop gets very hot and brightness wont change from max

    Hi i recently bought a laptop off my friend because my computer was very hard to read and i needed something smaller, it is only a year old and has a AMD A10 processor. Yesterday we recently tried to factory reset it and reinstall back to windows 8.1 to wipe data, we had a bit of a problem and it took a few hours due to the blue screen problem but i finally got it to boot, after installing windows i have noticed there was barely any programs on the computer except for internet explorer, i also noticed the brightness was on maximum and would not change from there i press the buttons adn the slider will go down but it wont actually change, this makes it very uncomfortable for eyes to read at night or in a dark room. i am also noticing that on the left hand side near the fan the laptop gets very very hot much hotter than my old intel i5 hp laptop, could you please help with these issues ASAP as it is driving me crazy and he wont even take the laptop back until i can fix the overheating and brightness issues. thanks very much

    i believe the model number is 15-n268sa

  • How to get the Full and final settelment date from PC_payresults

    Hi Experts..sairam.
    We are preparing Functional specification  for a report on Full and final settelement.
    We need to extract the  full and final settelement date from  payresults.
    Full and final settelement would be an offcycle run.
    How can we identify the particular Offcycle is meant for full and final settelment.
    Full and final settelement can be done after date of relieving.
    Please share your ideas to get the field names and logic to fetch.
    Thanks in advance.
    Regards,
    Sairam.

    Hi Praveen,
    I found it from HRPY_RGDIR through SE11.
    But im in confusion in thinking on Logic to find the Full and final settelment processed date.
    First of all..Report has to check WPBP table weather Employment status is Zero.
    Later..It has to read the HRPY_RGDIR table.
    Here what the system to check.What conditions to be validated to fetch the Full and final settelment processed date.Will it be FPPER and INPER as 00000000 or shall we do it from offcycle reason.
    Please share your ideas.Thanks in advance.
    Regards,Sairam.

  • Cannot view video get error message and only sound.

    cannot view video, get error message and sound only. Message  Error Code:c000005, address:2568b7ab

    I am just finally posting a reply. Looks as though the sound card went out. I was told that I could purchase a new open and install myself. I did not do that, but rather my step-dad just decided it was time to buy a new Mac Mini.

Maybe you are looking for