Getting the -1 node, -2 node of a hierarchy without using hierarchical q.

Hi,
I have two tables similar to:
SQL> desc strdet;
Name          Type         Nullable Default Comments
COSTCENTERMS  VARCHAR2(2)  Y                        
COSTCENTERDET VARCHAR2(2)  Y                        
HIERARCHYPATH VARCHAR2(20) Y
and the table levels..
desc levels;
Name       Type         Nullable Default Comments
LEVELID    NUMBER(1)    Y                        
LEVELDESCR VARCHAR2(20) Ywith sample data as:
insert into strdet values(1,20,'1');
insert into strdet values(20,3,'1.20');
insert into strdet values(3,40,'1.20.3');
insert into strdet values(20,50,'1.20');
insert into strdet values(50,6,'1.20.50');
insert into levels values(1,'level1');
insert into levels values(2,'level2');
insert into levels values(3,'level3');
insert into levels values(4,'level4');
I constructed a query...
select costcenter , h , levelid, leveldescr,
   decode(x,3,substr(h,instr(h,'.',1,1)+1,length(costcenterms)),
            4,substr(h,instr(h,'.',1,2)+1,length(costcenterms))) l_1
from levels ,
select costcenterms, costcenter, h ,
    case when instr(h,'.',1,3)>0 then 4
         when instr(h,'.',1,2)>0 then 3
         when instr(h,'.',1,1)>0 then 2
         when instr(h,'.',1,1)=0 then 1
       end x
from
select costcenterms, costcenterdet costcenter, hierarchypath||'.'||costcenterdet h
from strdet
union
select costcenterms, costcenterms costcenter, costcenterms h
from strdet
where costcenterms not in (select costcenterdet from strdet)
where levels.levelid=x
COSTCENTER H                       LEVELID LEVELDESCR           L_1
1          1                             1 level 1             
20         1.20                          2 level 2             
3          1.20.3                        3 level 3              20
50         1.20.50                       3 level 3              20
40         1.20.3.40                     4 level 4              3
6          1.20.50.6                     4 level 4              50
6 rows selectedNow, i desire to get the following result set(with the addition of L_2 column):
COSTCENTER H                       LEVELID LEVELDESCR           L_1          L_2
1          1                             1 level 1             
20         1.20                          2 level 2             
3          1.20.3                        3 level 3              20           1
50         1.20.50                       3 level 3              20           1
40         1.20.3.40                     4 level 4              3            20
6          1.20.50.6                     4 level 4              50           20Note: I use DB 10g v.2
Thank you,
Sim

Hi, Sim,
So you want to find the grandparent of each node, is that it?
You have all the ancestors in the string h; you just have to pick the right one out of h.
In Oracle 10 (and up) you can use REGEXP_SUBSTR to get the n-th item from a dot-delimited string like this:
REGEXP_SUBSTR ( h
           , '[^.]+'
           , 1
           , n
           )You just want to replace n with levelid-2. However, that 4th argument (n) must be positive, so you need to do something like this:
CASE
     WHEN     levelid < 3
     THEN     NULL
     ELSE     REGEXP_SUBSTR ( h
                     , '[^.]+'
                     , 1
                     , levelid
ENDI'm curious: why don't you want to use CONNECT BY?

Similar Messages

  • How to get the selected node value of a tree which is build on java code

    Hi Experts,
    How can i get the selected node value if I build the tree programatically.
    I am using the following code in selectionListener but it is throwing error.
    RichTreeTable treeTable = (RichTreeTable)getQaReasontreeTable();
    CollectionModel _tableModel =
    (CollectionModel)treeTable.getValue();
    RowKeySet _selectedRowData = treeTable.getSelectedRowKeys();
    Iterator rksIterator = _selectedRowData.iterator();
    String selectedQaCode ="";
    while (rksIterator.hasNext()) {
    List key = (List)rksIterator.next();
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    JUCtrlHierNodeBinding nodeBinding =
    treeTableBinding.findNodeByKeyPath(key);
    String nodeStuctureDefname =
    nodeBinding.getHierTypeBinding().getStructureDefName();
    selectedQaCode = selectedQaCode + nodeBinding.getAttribute(0);
    where I am using following link to create a tree with java code.
    http://one-size-doesnt-fit-all.blogspot.com/2007/05/back-to-programming-programmatic-adf.html
    Please help me in resolving this issue.
    Regards
    Gayaz

    Hi,
    you should also move
    JUCtrlHierBinding treeTableBinding =
    (JUCtrlHierBinding)((CollectionModel)treeTable.getValue()).getWrappedData();
    out of the while loop as this is not necessary to be repeated for each key in the set
    Frank

  • How to get the current node element by its value?

    e.g,:
    wdContext.current<b>Deal</b>Element().setAttributeValue("<i>deal_id</i>","<i>aaaaaaa</i>");
    above code can get the result i wanna.
    but now i wanna in terms of its node'name to  set attribute vaue of itself. in other words,i have no idea about how to get the current node element by its name"<b>Deal</b>".

    Hi Wing,
    The answer is there in your question itself.
    wdContext.currentDealElement()
    will give you the current node element by its name"Deal" or you could use
    wdContext.nodeDeal().getCurrentElement()
    or you could use
    wdContext.nodeDeal().getElementAt(wdContext.nodeDeal().getLeadSelection())
    Regards,
    Sudeep

  • How to get the Change node in Production Server!!!!!

    Hi Guys,
    Kindly let me know how to get the Change node in Production Server for the Transaction Code Pe03 for generating the Acknowledgement No for the year 2008 .
    Plz provide me the steps how to get the Change Node for Acknowledgement No so tat i can get the configuration done.
    Regards
    Ansuman Mohanty.

    Hi Mr!
    If you want to generate the e-file feature 40ACK, do it in our Customization client box (Golden box) & save the request & move to Quality & production.
    Still if you need to workout only in Production, than with the help of Basis people you can get the Production change mode for 5 to 10 min time & can generate it. But mostly Basis people wont give us change mode for Production box ... with ur request they can do..try it.
    Did u collected 4 quarter TAN no's for 2008 Quarter...if not collect it & generate it at a time.
    All the best:-)
    Kind Regards,
    Saisree.S

  • I can't get the correct node (a real beginner)

    I have an XML file which looks like this:
    [code<lawyer>
         <Country>Singapore</Country>
         <Company>Allen & Gledhill</Company>
    </lawyer>
    <lawyer>
         <Country>Singapore</Country>
         <Company>Allen & Gledhill</Company>
    </lawyer>.
    </Lawyers>
    But I can't get the right node names and values.
    Here is my code:
    File file = new File("lawyers.xml");
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(file);
    NodeList nlLawyers = doc.getElementsByTagName("lawyer");
    for (int i = 0; i < nlLawyers.getLength(); i++) {
         Element elLawyer = (Element) nlLawyers.item(i);
         NodeList columns = elLawyer.getChildNodes();
         for (int j=0; j<columns.getLength(); j++) {
              Node col = columns.item(j);
              String colName = col.getNodeName();
              String colVal = col.getNodeValue();
              System.out.println(colName + ": " + colVal);
    }What I would like to print out would be something like this:
    Country: Singapore
    Company: Allen & GledhillBut I am getting extra nodes and cannot get the text values. Here is the output I am getting:
    #text:
    Country: null
    #text:
    Company: nullI don't understand this output at all. Please help me get the list of node names and values?
    Thank you.
    -Jeff

    It seems that the #text nodes represent the whitespace between the formal nodes. Also, the nodes that I want to extract have a NodeTypeValue of 1. Once I had determined that I had the correct node, I had to get its child node to get the text. Here is the final code:
    File file = new File("lawyers.xml");
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(file);
    NodeList nlLawyers = doc.getElementsByTagName("lawyer");
    for (int i = 0; i < nlLawyers.getLength(); i++) {
         lawyer = new Lawyer();
         Element elLawyer = (Element) nlLawyers.item(i);
         NodeList columns = elLawyer.getChildNodes();
         for (int j=0; j<columns.getLength(); j++) {
              Node col = columns.item(j);
              if (col.getNodeType() == 1) {
                   String strColumn = col.getNodeName();
                   Node txt = col.getFirstChild();
                   String strValue = txt.getNodeValue();
                   System.out.println(strColumn + ":\t" + strValue);                         }
         } // for each column
    } // for each lawyer

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • How to get the parent node of the current node?

    Hi all,
    i want to get the parent node of the current node and the not the parent of the parent node.
    thank you very much

    Hi,
    the parent node of <subnode1-2>29.99</subnode1-2> is (node1), how can do to get <node1> throw <subnode1-2>29.99</subnode1-2> the sub node of <node1>.
    As per my understanding the parent node of <subnode1-2>29.99</subnode1-2> is book not the node1.
    If you want node 1 as a parent of subnode1-2 than your xml will look like this.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <bookstore>
    <book>
    <fathernode>Harry Potter</fathernode>
    <node1>
           <subnode1>29.99</subnode1>
           <subnode2>29.99</subnode2>
    </node1>
    <node2>
           <subnode1>19.99</subnode1>
           <subnode2>19.99</subnode2>
    </node2>
    </book>
    </bookstore>
    and also if you want tom retrive float data than refer following XPATH.
    "//book[[price='1000']]/price/text()"
    Regards,
    Manoj Bilthare

  • How to get the leaf node in a hierachy????

    if i get a record that a parent node in a hierachy table ,so how can i get the leaf node of this parent node quicklly?????thank you!

    Hi xuhuanjun ,
    Refer to the below threads which disucss the same.
    Re: how to ensure a hierarchy tree's node is a internal leaf???????
    Re: Retrieve Hierarchy Leaf Node using API.
    Hope it helps.
    Thanks,
    Minaz

  • Tokenizer - getting the third node from this format (800,PA,PAC,Package)

    Hi Folks,
    I am trying to get the third node from the following format: 800,PA,PAC,Package
    The correct output is PAC.
    Your help is very much appreciated!
    Just to add the code that I have is as follows:
    Import com.sap.mw.jco.*;
    //write your code here
    String DBTABLE = a;
    String WHERE_CLAUSE = b+" = "+"'"c"'" ;
    //...some code in here...
    // Create function
    JCO.Function function = null;
    IFunctionTemplate ft = mRepository.getFunctionTemplate("RFC_READ_TABLE");
    function = ft.getFunction();
    // Obtain parameter list for function
    JCO.ParameterList input = function.getImportParameterList();
    // Pass function parameters
    input.setValue( DBTABLE, "QUERY_TABLE");
    input.setValue( "," , "DELIMITER");
    //Fill the where clause of the table
    JCO.ParameterList tabInput = function.getTableParameterList();
    JCO.Table inputTable = tabInput.getTable("OPTIONS");
    inputTable.appendRow();
    inputTable.setValue(WHERE_CLAUSE,"TEXT");
    mConnection.execute( function );
    //This is the part where the output is generated
    JCO.Table valueSet = function.getTableParameterList().getTable("DATA");
    String resultSet = valueSet.getString("WA"); //WA contains 800,PA,PAC,Package
    mConnection.disconnect();
    return resultSet;

    Hi Morgalr,
    Thank your for the tip.
    I am not sure if there is a better way to do the coding. But what what I have come up is the following:
    JCO.Table valueSet = function.getTableParameterList().getTable("DATA");
    String resultSet []= valueSet.getString("WA").split("(double \ in here),");
    mConnection.disconnect();
    return resultSet[2];
    Let me know if this works with you.
    regards,
    Lex

  • Using IClusterInformation Interface to get the server node.

    Hi ,
       I have created a portal application which contains an Abstract Portal Component to display the server node the user logs on.
    I have written the following code :
    IClusterInformation clusterContext =
    (IClusterInformation) PortalRuntime.getRuntimeResources().getService( IClusterInformation.KEY);
    I too added the Sharing Reference , "com.sap.portal.runtime.system.clusterinformation" to Application Config property in Portalapp.xml file.
    But still am getting an error "IClusterInformation cannot be resolved".
    Do I need to add some external JAR File to the Java Build Path of my portal Application. If so , Which JAR file I need to add?
    Regards,
    Eben Joyson.

    I use this to get the server - node:
    String node = "";
    Enumeration props = System.getProperties().keys();
    while (props.hasMoreElements()) {
      String thisProp = props.nextElement().toString();
      if (thisProp.startsWith("dsr.") && thisProp.endsWith(".buffersize")) {
        node = thisProp.substring(5 + thisProp.indexOf("_" + SID + "_"), thisProp.indexOf(".buffersize"));
          if (node != null) {
            String cluster = node.substring(0, 6) + "00";
            node = node.substring(0, 8);
    Hope it helps
    Johannes

  • I have a mac  book pro that i bought in late 2009. My current software is snow leopard version 10.5.8. I would like to get the new lion operating system but I cant without first getting the latest version of snow leopard. it doesnt show on software updat

    I have a mac book pro that i bought in late 2009. My current software is snow leopard version 10.5.8. I would like to get the new lion operating system but I cant without first getting the latest version of snow leopard. however when I go to update my software it doesnt show that any update is available.

    10.5.8 is Leopard, not Snow Leopard. You need the Snow Leopard DVD;
    You can get it only by phone now from Apple.
    In the US, call 1-800-MY-APPLE and ask for a sales assistant. Last quoted price was $19.99 for the single-user and $29.99 for the family licence.
    For other countries, check here; http://support.apple.com/kb/HE57
    Don't forget to ask for Sales; the tech support guys can't help.
    If you want Lion, rather than Mountain Lion, the same Sales team can give you a download code to use at the Mac AppStore.
    To get the App Store, you need to update your new Snow Leopard from 10.6.3 (which is the version on the installer) to 10.6.8 with the combo update; http://support.apple.com/kb/DL1399
    Be warned that the upgrades will render a lot of older software unusable, and will need new drivers for printers and scanners in all likelihood.

  • Iphone 4s coming friday, what is the best way to get the notes content from iphone 4 to 4s without doing a restore? i want the new phone to be totally new but not sure how to get notes content across.

    What is the best way to get the notes content from iphone 4 to 4s without doing a restore? i want the new phone to be totally new but not sure how to get notes content across. If I do a restore as I have when previously from one iphone to another it has shown (in settings, usage) the cumulative usage from previous phones so all the hours of calls on all previous iphones will be displayed even though its brand new. Anyone know how I can get my notes (from standard iphone notes app) to my new iphone 4s without restoring from previous iphone 4. Thanks for any help offered.

    First, if you haven't updated to iTunes 10.5, please update now as you will need it for the iPhone 4S and iOS 5.
    Once you're done installing iTunes 10.5, open it. Connect your iPhone to iTunes using the USB cable. Once your iPhone pops up right click on it. For example: an iPhone will appear and it will say "Ryan's iPhone."
    Right click on it and select "Backup" from the dropdown menu. It will start backing up. This should backup your notes.
    Please tell me if you have any problems with backing up.
    Once you backup and get your iPhone 4S, you must follow these steps. If you don't follow these steps, you will not be able to get your notes on your new iPhone 4S.
    Open up iTunes again then right click on your device (iPhone 4S). Once you do you will see a dropdown menu. It will say "Restore from Backup..." Select this and it'll ask for a backup, select it from the dropdown menu. For example "Ryan's iPhone - October 12, 2011." Pick that and it will restore to your backup. Do this when you get your iPhone 4S so you will not lose anything. Even though you're restoring, you're getting back, since you're getting the previous settings, notes, contacts, mail and other settings from your old iPhone. You'll still have Siri though! So, restore when you first get it. Also frequently backup your device, as it will be worth it. You can restore from a backup if something goes wrong or save your data for a future update.
    Once you do that, you should have your notes on your new iPhone 4S and iOS 5.
    Please tell me if you need any help.
    I hoped I answered your questions and solved your problem!

  • I am so confused.  I just downloaded Itunes.  I set up an Apple ID with a password.  Now I want to purchase a song.  I can't do it.  I keep getting the message: This Apple ID has not yet been used with the Itunes Store.  What am I doing wrong?

    I am so confused.  I just downloaded Itunes.  I set up an Apple ID with a password.  Now I want to buy a song.  I can't do it.  I keep getting the message: "This Apple ID has not yet been used with the Itunes Store.  What am I doing wrong?

    You haven't opened an account with that Apple ID in iTunes. Open iTunes and log in. A dialog will appear in which you need to enter your Apple ID and/or password. Below it you should see a link for creating a new account. Click on that link to get started.

  • How can I get the photos on my pc onto my Macbook without emailing each one individually to myself?

    How can I get the photos on my pc onto my Macbook without emailing each one individually to myself?

    Welcome to Apple Support Communities.
    Copy them from your PC to a flash drive or an external drive, then open iPhoto and select Import to Library.
    Depending on your settings, iPhoto might open automatically and ask if you want to import them when the device (camera or flash drive or external drive) containing the images is connected.
    At the end of the import, iPhoto will ask if you want to delete or keep the photos on the other device. Keep until you're absolutely certain all images are imported correctly and you've viewed them in iPhoto. It's always nice to have a backup.

  • How can I get the number of rows in my sql result, without a loop?

    Hello,
    I've a problem, I would like to get the number of rows in my sql result without make a loop like :
    while (rs.next()){
    int number = rs.getRow();
    Is there any method to do this, on the first element?
    Thx, STeF

    If you want to count how many rows are in result set, I dont think you can, but you could always run a count statement for that sql
    say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......
    then you can count the rows this statement returns by
    select count(*) from
    (say your sql is
    select field1, field2, field3
    from table1, table2
    where field4=field5 ......)
    This way you will get the count for just that sql

Maybe you are looking for

  • Help on regular expression

    hi all i need to validate telephone number , and i tried to use the following expression : "[\\d][\\d][\\d]-[\\d][\\d][\\d][\\d]" or "[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]" they did not seem to work. can anyone provide some help on this? thanks in adv

  • Using xml file in java application

    How can i get the attribute name & value into my java application from a xml flie?

  • Clearing with Vendor.

    Dear Expert, When we clear Vendor open items with Customer opern items either the reconciliation accounts are effected with the transaction amount or not. Regards Aly Lakson Group, Pakistan

  • Lockbox issue - Very urgent....

    Hi all, If a payment from the lockbox file is erroneously put ‘On account” for a customer since it was unprocessed and later the user has realized that the payment does not belong to that customer also it is not related to any customer so, he wants t

  • TA20406 how do I put a video on HTML in a mac?

    <html> </html>